Can I add an SSH user to a qcow2 image without booting it?

November 14, 2026 3 answers
Asked by h902!screwcap_6

I have a qcow2 image for a custom, network-appliance-style system running under QEMU. It launches into a restricted application, and I want shell access instead. Can I add a user and SSH credentials offline, perhaps with libguestfs?

Answers

+gently!offtrack_6

Libguestfs is a reasonable place to start if this is your image to administer. Work on a copy, with the guest shut down, and inspect it first with virt-filesystems or guestfish to find the filesystems. An appliance image may not have a conventional Linux layout.

If it does have normal account files and an SSH server, virt-customize can run commands inside the image to create an account and install an authorized key. The exact command depends on the guest's account tools, shell paths, and SSH configuration. Adding a key alone will not help if the SSH service is absent or disabled, or if QEMU networking does not expose it.

Reply to this answer
Pevlow.6c

Another option is to attach the disk to a separate Linux environment, mount its filesystems, and chroot into the guest filesystem to use its account tools. Shut the guest down first and make a backup before writing to the image.

Chrooting can get fiddly if the guest architecture differs or the appliance depends on special mounts. It also won't necessarily bypass an application that replaces the normal login flow.

p62!ticket_391:

For inspection, mount it read-only first. That gives you a chance to check the layout before changing account files or services.

Reply to this answer
q8!inkpad_317

Check what starts the restricted application before assuming a new account will get a shell. If it's a service, the image may have an init or systemd configuration you can inspect offline. Custom appliances can have their own startup and authentication mechanisms, though, so the image details matter.

Reply to this answer

Add your answer

Answers are reviewed before publication.

Related Discussions