SSH
5.1
SSH logs you in to another machine, runs commands there and copies files, over an encrypted link. Every SliTaz image has Dropbear, a small SSH server and client; OpenSSH is a package. The Handbook gives the basics in Servers: SSH; this page goes further, with the small SliTaz scripts built around Dropbear.
Dropbear or OpenSSH
- Dropbear is on every image. It gives the server
dropbear, the clientdbclient(also calledssh),scp, and the key toolsdropbearkeyanddropbearconvert. Its files are in/etc/dropbear/. - OpenSSH is installed with
spk-add openssh. It bringsssh,scp,sftp,ssh-keygen,ssh-copy-id,ssh-agentand the serversshd, and replaces thesshandscpcommands of Dropbear. Its files are in/etc/ssh/, the server settings in/etc/ssh/sshd_config, and the service isopenssh.
Dropbear is enough for most uses. Run only one server: both listen on port 22.
Connect and copy files
$ ssh tux@192.168.1.10
$ ssh -p 2222 tux@192.168.1.10
$ scp notes.txt tux@192.168.1.10:Documents/
$ scp tux@192.168.1.10:Documents/notes.txt .
The first time, the client asks you to accept the key of the server
and keeps it in ~/.ssh/known_hosts.
The Dropbear server
The server does not start by default. As root:
# trame service start dropbear
# trame service enable dropbear
The first line starts it now, the second at every boot (it adds
dropbear to RUN_DAEMONS in /etc/rcS.conf). The script is
/etc/init.d/dropbear, with start, stop and restart.
At its first start, the script makes the host keys (rsa, ecdsa and
ed25519) in /etc/dropbear/. To see the fingerprint of a key, to
check it from a client:
# dropbearkey -y -f /etc/dropbear/dropbear_ed25519_host_key
The options of the server are in DROPBEAR_OPTIONS, in
/etc/daemons.conf. The default is:
DROPBEAR_OPTIONS="-w -g -b /etc/dropbear/banner"
-w: root cannot log in. Log in as a user, then usesu.-g: no password login for root.-b: show the text of/etc/dropbear/bannerbefore the login.
Useful additions: -s to allow key logins only, -p 2222 to listen on
another port. dropbear -h lists all of them. Restart the server after
a change:
# trame service restart dropbear
When iptables is installed, the script also adds firewall rules against password guessing: an address that opens more than 5 new connections to port 22 within 5 minutes is blocked for a while, and logged with the prefix "SSH-Bruteforce".
Log in with a key
A key login needs no password and is safer. Dropbear looks for the key
of the client in ~/.ssh/id_dropbear. Make it, then add its public
part to ~/.ssh/authorized_keys on the server:
$ mkdir -p ~/.ssh
$ dropbearkey -t ed25519 -f ~/.ssh/id_dropbear
$ dropbearkey -y -f ~/.ssh/id_dropbear | grep ^ssh- | \
ssh tux@192.168.1.10 'umask 077; mkdir -p .ssh; cat >> .ssh/authorized_keys'
With OpenSSH, use ssh-keygen -t ed25519 then
ssh-copy-id tux@192.168.1.10. To use an OpenSSH key with Dropbear,
convert it:
$ dropbearconvert openssh dropbear ~/.ssh/id_ed25519 ~/.ssh/id_dropbear
When the key works, you can add -s to DROPBEAR_OPTIONS to refuse
passwords.
SliTaz extras
The dropbear package of SliTaz brings three small scripts that other distributions do not have.
Remote X programs
The Dropbear server can forward X11, its client cannot. The script
sshx fills the gap: with DISPLAY set, it opens a terminal of the
remote machine on your screen, or runs the program you give it:
$ sshx tux@192.168.1.10 lxterminal
sshx tunnels the display to the X server on 127.0.0.1, port 6000.
The LXTaz login manager starts X with -nolisten tcp, so on SliTaz
5.1 sshx, and the "Remote terminal" entry of the menu that uses it,
do not get the remote window. Use the OpenSSH client instead.
With OpenSSH installed, ssh -X forwards X on its own:
$ ssh -X tux@192.168.1.10 lxterminal
The server needs the xauth program. On an OpenSSH server, also set
X11Forwarding yes in /etc/ssh/sshd_config.
VNC through SSH
fbvnc is a tiny VNC viewer for the text console, in BusyBox. VNC
itself has no encryption. sshfbvnc opens an SSH tunnel to the VNC
server of the remote machine, then runs fbvnc through it:
$ sshfbvnc tux@192.168.1.10
Add the VNC port after the address if it is not 5900. See Remote desktop.
A VPN over SSH
pppssh makes a small VPN: PPP over an SSH link. It needs the ppp
package on both sides, root on your side and the right to run pppd
on the server. Run it without arguments for its usage. Being TCP
based, it adds delays: fine for a shell or files, not for voice. See
VPN.
Mount a remote directory
spk-add sshfs-fuse gives sshfs, to mount a directory of a remote
machine over SSH, and rsshfs, which does the reverse: it mounts a
directory of your machine on the remote one (that one needs sshfs
too):
$ sshfs tux@192.168.1.10:Documents ~/remote
$ fusermount3 -u ~/remote
$ rsshfs /home/tux/share tux@192.168.1.10:/home/tux/mnt
$ rsshfs -u tux@192.168.1.10:/home/tux/mnt
Troubleshooting
"Connection refused": no server runs on the machine. Check with
trame service status dropbear.
Root cannot log in: that is the -w option. Log in as a user, then
su.
Blocked after a few logins: the rules against password guessing above. Wait five minutes, or use a key and a single connection.
The client refuses the key of the server: the machine was
reinstalled or got new keys. If you trust it, remove its line from
~/.ssh/known_hosts.
OpenSSH prints "unknown key type dsa" at start: the script still tries to make a DSA key, which OpenSSH no longer supports. It is harmless: the other keys are made and the server starts.
Links
- Handbook: Servers: SSH
- Dropbear
- OpenSSH