mkj/dropbear
repository·main·Indexed 25 days ago
https://github.com/mkj/dropbearA lightweight SSH server including Debian packaging instructions and integration with the runit service supervision system. The repository provides documentation on configuring public key authentication, converting OpenSSH keys using dropbearconvert, generating host keys with dropbearkey, and building the server with various configurations including diet libc, uClibc, and static linking. It also includes details on the LibTomMath MPI library used for high-precision integer arithmetic.
What's inside mkj-dropbear
- LibTomMath is a free, open-source, portable number theoretic multiple-precision integer (MPI) library written entirely in C. It provides algorithms for high-precision integer arithmetic.
Special hardware and PTY considerations
main386-class CPUs
If compiling for a 386-class CPU, you must add
CFLAGS=-DLTC_NO_BSWAPto preventlibtomcryptfrom using 486+ instructions.PTY Allocation
Dropbear attempts to detect the best PTY allocation method automatically. If
openpty()(whereHAVE_OPENPTYis defined inconfig.h) fails, you can use--disable-openpty, but be aware this may require manual device creation for/dev/pty??and/dev/tty??.Compile the standalone SCP program
mainThe Dropbear distribution includes a standalone version of OpenSSH's
scp.Compilation steps:
- Run
make scpto build the binary. - Customizing the SSH path: If you need to change the path to the ssh binary, modify
_PATH_SSH_PROGRAMinoptions.hbefore compiling. - Enabling the progress meter: By default, the progress meter is disabled to save space. To enable it, include
SCPPROGRESS=1in yourmakecommand.
- Run
Configure Server Public Key Authentication
mainDropbear supports public key authentication using the
~/.ssh/authorized_keysfile, following the same convention as OpenSSH.Requirements:
- Key entries must be in the standard format:
ssh-rsa <KEY_DATA> <COMMENT>. - Permissions must be strictly enforced:
~/.sshand the key files must be writable only by the user. - Warning: Avoid using text editors that automatically split long key strings into multiple lines, as this will break the key.
For advanced options for
authorized_keysentries, refer to the local manpage.ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAIEAwVa6M6cGVmUcLl2cFzkxEoJd06Ub4bVDsYrWvXhvUV+ZAM9uGuewZBDoAqNKJxoIn0Hyd0NkyU99UVv6NWV/5YSHtnf35LKds56j7cuzoQpFIdjNwdxAN0PCET/MG8qyskG/2IE2DPNIaJ3Wy+Ws4IZEgdJgPlTYUBWWtCWOGc= someone@hostname- Key entries must be in the standard format:
Compile Dropbear for uClibc
mainWhen compiling for uClibc, ensure you are using at least uClibc 0.9.17 to avoid broken
getusershell()behavior.Steps for uClibc
- Set the compiler to your uClibc toolchain (e.g.,
export CC=i386-uclibc-gcc). - Use
make STATIC=1for statically linked binaries. - Use
make stripto reduce binary size. - To include
zlibmanually, copyzlib.handzconf.hinto a subdirectory (e.g.,zlibincludes) and set the following flags before configuring:
export CFLAGS="-Izlibincludes -I../zlibincludes" export LDFLAGS=/usr/lib/libz.aImportant Notes
- Header Mismatch: Ensure your libc headers match the library version being used to avoid issues like shadow password support mismatches.
- zlib Disabling: If you disable zlib, you must explicitly disable compression for the client. You may need to disable it globally in
~/.ssh/config.
export CC=i386-uclibc-gcc export CFLAGS="-Izlibincludes -I../zlibincludes" export LDFLAGS=/usr/lib/libz.a ./configure make STATIC=1 make strip- Set the compiler to your uClibc toolchain (e.g.,
Build and install LibTomMath
mainThe project is built using
make. Standard targets include:make: Build the library.make clean: Remove build artifacts.make install: Install the library to the system.
Note: For detailed instructions on building specifically for GNU Linux, refer to the "Building LibTomMath" section in the
doc/bn.pdfdocumentation.make make clean make installRun LibTomMath tests
mainTests are located in the
demo/directory and can be executed in two different modes:Standalone Tests: Creates a single binary that runs several internal test routines.
- Command:
make test
- Command:
Opponent Testing (mtest): A specialized mode where
libtommath(the 'opponent') is tested against test vectors generated by an alternative MPI library (mtest).- Build the opponent:
make mtest_opponent - Build the generator:
make mtest - Execute the test:
./mtest/mtest | ./mtest_opponent
- Build the opponent:
# Standalone test make test # Opponent test against mtest make mtest make mtest_opponent ./mtest/mtest | ./mtest_opponentConfigure and build Dropbear
mainTo build Dropbear, follow the standard autotools workflow: run
./configure, thenmake.Configuration Options
--disable-zlib: Disables zlib support.--disable-syslog: Disables syslog support.--enable-static: Compiles with static linking.--disable-harden: Disables build flags intended to improve robustness against programming bugs.--disable-lastlog: Manually disables lastlog recording (recommended for uClibc).--disable-openpty: Disablesopenpty()for PTY allocation if it fails. Note that you may need to manually create/dev/pty??and/dev/tty??devices if you use this.--help: Displays all available configuration options.
Compilation
You can specify which programs to build using the
PROGRAMSvariable. Common programs includedropbear,dbclient,dropbearkey,dropbearconvert, andscp.Warning: If you change the
PROGRAMSlist and recompile, you MUST runmake cleanbefore recompiling to avoid build errors.# Configure ./configure --enable-static # Compile specific programs make PROGRAMS="dropbear dbclient dropbearkey dropbearconvert scp" # Install to default (/usr/local/bin) make install # Install to a temporary directory for testing make install DESTDIR=/same/temp/locationConvert OpenSSH keys for use with Dropbear Client
mainWhen using Dropbear as a client (
dbclient), you cannot use OpenSSH-style private keys directly. You must convert them to the Dropbear format usingdropbearconvert.To convert an OpenSSH private key and then connect to a host:
- Convert the key using
dropbearconvert openssh dropbear <input_path> <output_path>. - Use the converted key with
dbclient -i.
dropbearconvert openssh dropbear ~/.ssh/id_rsa ~/.ssh/id_rsa.db dbclient -i ~/.ssh/id_rsa.db <hostname>- Convert the key using
Generate or convert Dropbear Server Host Keys
mainThe Dropbear server requires host keys to function. You can either generate new keys using
dropbearkeyor convert existing OpenSSH host keys usingdropbearconvert.Option 1: Generate new keys Run
dropbearkeyfor each required algorithm (rsa, dss, ecdsa, ed25519).Option 2: Convert OpenSSH keys Use
dropbearconvert openssh dropbear <openssh_key_path> <dropbear_key_path>.Option 3: Automatic generation To have Dropbear automatically generate keys upon the first connection, ensure the
/etc/dropbear/directory exists and start the server with the-Rflag.# Generate new keys ./dropbearkey -t rsa -f dropbear_rsa_host_key ./dropbearkey -t dss -f dropbear_dss_host_key ./dropbearkey -t ecdsa -f dropbear_ecdsa_host_key ./dropbearkey -t ed25519 -f dropbear_ed25519_host_key # Alternatively, convert OpenSSH keys ./dropbearconvert openssh dropbear /etc/ssh/ssh_host_dsa_key dropbear_dss_host_keyCustomize build options via localoptions.h
mainDropbear allows fine-grained configuration of cryptographic algorithms, SSH features, and file paths through header files.
localoptions.h: Located in the build directory. This is a local file (not tracked by git) where you can define custom build options. Use this to remove unneeded ciphers and algorithms to reduce binary size.src/default_options.h: Contains the default available options.src/distrooptions.h: Used by distributions to set specific configuration options if the file exists.
Run Dropbear concurrently with OpenSSH 'sshd'
mainBy default, if OpenSSH is installed, Dropbear is configured not to start to avoid port conflicts on port 22. To run both services simultaneously, you must modify the Dropbear configuration file to allow it to start and assign it a different port than OpenSSH.
- Open
/etc/default/dropbearin an editor. - Set
NO_STARTto0. - Change the port number assigned to Dropbear to something other than 22.
- Open