mkj/dropbear

repository·main·Indexed 25 days ago

https://github.com/mkj/dropbear

A 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.

Tokens
3.3K
Snippets
10
Records
18
Agent score
82%

What's inside mkj-dropbear

  1. Special hardware and PTY considerations

    main

    386-class CPUs

    If compiling for a 386-class CPU, you must add CFLAGS=-DLTC_NO_BSWAP to prevent libtomcrypt from using 486+ instructions.

    PTY Allocation

    Dropbear attempts to detect the best PTY allocation method automatically. If openpty() (where HAVE_OPENPTY is defined in config.h) fails, you can use --disable-openpty, but be aware this may require manual device creation for /dev/pty?? and /dev/tty??.

  2. Compile the standalone SCP program

    main

    The Dropbear distribution includes a standalone version of OpenSSH's scp.

    Compilation steps:

    • Run make scp to build the binary.
    • Customizing the SSH path: If you need to change the path to the ssh binary, modify _PATH_SSH_PROGRAM in options.h before compiling.
    • Enabling the progress meter: By default, the progress meter is disabled to save space. To enable it, include SCPPROGRESS=1 in your make command.
  3. Configure Server Public Key Authentication

    main

    Dropbear supports public key authentication using the ~/.ssh/authorized_keys file, 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: ~/.ssh and 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_keys entries, refer to the local manpage.

    ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAIEAwVa6M6cGVmUcLl2cFzkxEoJd06Ub4bVDsYrWvXhvUV+ZAM9uGuewZBDoAqNKJxoIn0Hyd0NkyU99UVv6NWV/5YSHtnf35LKds56j7cuzoQpFIdjNwdxAN0PCET/MG8qyskG/2IE2DPNIaJ3Wy+Ws4IZEgdJgPlTYUBWWtCWOGc= someone@hostname
  4. Compile Dropbear for uClibc

    main

    When compiling for uClibc, ensure you are using at least uClibc 0.9.17 to avoid broken getusershell() behavior.

    Steps for uClibc

    1. Set the compiler to your uClibc toolchain (e.g., export CC=i386-uclibc-gcc).
    2. Use make STATIC=1 for statically linked binaries.
    3. Use make strip to reduce binary size.
    4. To include zlib manually, copy zlib.h and zconf.h into a subdirectory (e.g., zlibincludes) and set the following flags before configuring:
    export CFLAGS="-Izlibincludes -I../zlibincludes"
    export LDFLAGS=/usr/lib/libz.a

    Important 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
  5. Build and install LibTomMath

    main

    The 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.pdf documentation.

    make
    make clean
    make install
  6. Run LibTomMath tests

    main

    Tests are located in the demo/ directory and can be executed in two different modes:

    1. Standalone Tests: Creates a single binary that runs several internal test routines.

      • Command: make test
    2. 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
    # Standalone test
    make test
    
    # Opponent test against mtest
    make mtest
    make mtest_opponent
    ./mtest/mtest | ./mtest_opponent
  7. Configure and build Dropbear

    main

    To build Dropbear, follow the standard autotools workflow: run ./configure, then make.

    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: Disables openpty() 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 PROGRAMS variable. Common programs include dropbear, dbclient, dropbearkey, dropbearconvert, and scp.

    Warning: If you change the PROGRAMS list and recompile, you MUST run make clean before 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/location
  8. Convert OpenSSH keys for use with Dropbear Client

    main

    When using Dropbear as a client (dbclient), you cannot use OpenSSH-style private keys directly. You must convert them to the Dropbear format using dropbearconvert.

    To convert an OpenSSH private key and then connect to a host:

    1. Convert the key using dropbearconvert openssh dropbear <input_path> <output_path>.
    2. Use the converted key with dbclient -i.
    dropbearconvert openssh dropbear ~/.ssh/id_rsa  ~/.ssh/id_rsa.db
    dbclient -i ~/.ssh/id_rsa.db <hostname>
  9. Generate or convert Dropbear Server Host Keys

    main

    The Dropbear server requires host keys to function. You can either generate new keys using dropbearkey or convert existing OpenSSH host keys using dropbearconvert.

    Option 1: Generate new keys Run dropbearkey for 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 -R flag.

    # 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_key
  10. Customize build options via localoptions.h

    main

    Dropbear 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.
  11. Run Dropbear concurrently with OpenSSH 'sshd'

    main

    By 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.

    1. Open /etc/default/dropbear in an editor.
    2. Set NO_START to 0.
    3. Change the port number assigned to Dropbear to something other than 22.