Dropbear calls the
getpwnam standard library function to get information about user accounts. On systems with GNU libc (the standard library for non-embedded Linux systems), this function can query several types of databases through the NSS mechanism, including
/etc/passwd. Embedded systems may run a variety of libc (uClibc, dietlibc, …), and they tend to have the path
/etc/passwd baked in.
Short of patching and recompiling dropbear (or your libc), you're going to have to supply that
/etc/passwd file somehow. There are ways to make extra files appear on top of a read-only filesystem, not by modifying the filesystem, but instead by instructing the kernel to supply files from a different filesystem at these locations. The generic mechanism is a union mount, but embedded Linux systems often lack a good union mount feature.
A relatively simply way to override a filesystem location with different content is
mount --bind. After running the command
mount --bind /else/where /some/where
, any access to a file/some/where/somefile
actually accesses the file/else/where/somefile
; any file in the “true”/else/where
is hidden. However, you cannot directly make a file appear this way: both/else/where
have to exist (although they don't have to be directories). So you can't make/etc/passwd
come into existence, but you can override/etc`.
Create a directory that will contain your replacement for
/etc. Let's say it's
Create a mount point where you'll relocate the original
Create symbolic links in the replacement
etc to files in the original.
for x in *; do ln -s "../original-etc/$x" "/custom/etc/$x"; done
passwd file in your replacement
echo "root:x:0:0:root:/:/bin/sh" >/custom/etc/passwd
At boot time, first perform a bind mount to create a view of the original
/etc hierarchy at
/custom/original-etc, then perform a bind mount to create a view of your replacement
/etc. Put these commands in a script that is executed during startup (the same script where you start the dropbear server, obviously before starting dropbear).
mount --bind /etc /custom/original-etc
mount --bind /custom/etc /etc