axel@beckert.ch
http://axel.beckert.ch/
Verifying the identity of an SSH server by its host keys
ssh-keygen -l -f /etc/ssh/ssh_host_<algorithm>_key.pub
(adds .pub
automatically if omitted):
$ ssh-keygen -l -f /etc/ssh/ssh_host_ecdsa_key 256 fd:89:37:8e:f0:76:f0:c9:47:ee:73:31:0f:48:fe:20 root@c-cactus (ECDSA)
GET https://db.debian.org/debian_known_hosts > ~/.ssh/known_hosts2
(~/.ssh/known_hosts
and~/.ssh/known_hosts2
are both checked by default. How convenient! :-)Verifying SSH Host Keys via DNS — DNSSEC recommended
ssh-keygen -r <hostname>
:
$ ssh-keygen -r c-cactus.deuxchevaux.org c-cactus.deuxchevaux.org IN SSHFP 1 1 8270d67451d29af5b2cc3d0a00c2df20060746fa c-cactus.deuxchevaux.org IN SSHFP 1 2 7683a04bbd2dbbae9c6d487493c251de69100287e09fa6c72d7d74555c8a4912 c-cactus.deuxchevaux.org IN SSHFP 2 1 f43b0e9d2367bf6cd47fb405288d7304a10a41d9 c-cactus.deuxchevaux.org IN SSHFP 2 2 0e6b6d17e1565ec05d9c400abda79eae935e44b6a1faa22d20083d38c517f7b9
host -t SSHFP <hostname>
:
$ host -t SSHFP www.ccczh.ch www.ccczh.ch is an alias for proxy.ccczh.ch. proxy.ccczh.ch has SSHFP record 3 1 CC60D7A88E96BDAD570EAA39CDC86FED proxy.ccczh.ch has SSHFP record 1 1 9BA56C02A0A82E2BED5D946413E6A62B proxy.ccczh.ch has SSHFP record 2 1 99C0844B0A0692EEC6601B5ACBDC81D5
ssh -o "VerifyHostKeyDNS ask" <hostname>
:
$ ssh -o "VerifyHostKeyDNS ask" host.example.com […] Matching host key fingerprint found in DNS. Are you sure you want to continue connecting (yes/no)?
SSH Keys for Authentication and Authorization
ssh-keygen
(only in special cases without passphrase!)ssh-copy-id
(copies key(s) into the remote ~/.ssh/authorized_keys
)eval `ssh-agent`
(often started via Xsession)ssh-add
ssh-add -l
(List fingerprints) /
ssh-add -L
(List public key parameters)ssh other.computer -t -A ssh-add
(Loading key from other computer into the local key agent.)ssh-add -x
(Lock)ssh-add -X
(Unlock)ssh -A
(Forward Agent)ssh -a
(Don't forward Agent)Host *.deuxchevaux.org *.noone.org ForwardAgent yes
Transfering files with SSH
$ scp file myaccount@computer:directory/ file 100% 337 0.3KB/s 00:00
$ sftp myaccount@computer Connecting to rechner... sftp> ls file1 file2 sftp> get file1 Fetching /home/myaccount/file1 to file1 /home/abe/file1 100% 337 0.3KB/s 00:00 sftp> lls file1 file3 sftp> put file3 Uploading file3 to /home/myaccount/file3 file3 100% 65 0.1KB/s 00:00 sftp> quit
$EDITOR ~/.ssh/config
Host * HashKnownHosts no NoHostAuthenticationForLocalhost yes Host sym HostName symlink.to.noone.org ForwardAgent yes ForwardX11Trusted yes Host sf Hostname shell.sourceforge.net User xtaran Host avaya StrictHostKeyChecking no UserKnownHostsFile /dev/null
$EDITOR ~/.ssh/config
# OpenSSH < 5.4 Host myhomeserver ProxyCommand ssh myhomegateway nc myhomeserver 22 # OpenSSH ≥ 5.4 Host myhomeserver ProxyCommand ssh myhomegateway -W myhomeserver:22
$EDITOR ~/.ssh/config
Host host-with-picky-firewall ControlMaster autoask ControlPath ~/.ssh-master-%l-%h-%p-%r
rsh
by default.rsh
may be a symbolic link to ssh
if rsh is not installedset tunnel="ssh -q imap.example.org /etc/rimapd"
)inbox-path={imap.example.org/user=myaccount/secure}INBOX folder-collections=Mail {imap.example.org/user=myaccount/secure}[] rsh-open-timeout=0 ssh-path=/usr/bin/ssh
ssh
can setup the right tunnel and $DISPLAY
automatically.
Needs xauth
in the search path on the remote computer.-X
or ForwardX11 yes
-Y
or ForwardX11 yes
+ ForwardX11Trusted yes
(Details in ssh_config(5)
)-x
or ForwardX11 no
-g
to allow access from everywhere.ssh -L 8080:proxy:8080 router.at.home
(Use the proxy at home from elsewhere)ssh -R 8000:localhost:8001 company.computer
(Give a computer at work access to your local web server)ssh -R 8000:localhost:8001 -g company.computer
(Give all computers at work access to your local web server)Using SSH as SOCKS proxy
ssh -D 1080 remote.computer
and configure
localhost:1080
as SOCKS proxy in your browser,
e-mail client, other program or with tsocks
.<Enter>~
nothing seems to happen.~
) after an Enter is the escape sequence of SSH~~
results in one tilde~.
disconnects immediately~<Ctrl-Z>
stops the SSH (continue with fg
)~&
puts the SSH in the backgound, e.g. in case there are still tunnels open after logging out.~?
shows the help.GNU Screen allow one (amongst other things) to continue to use shell sessions and other text mode programs (e.g. mutt, irssi, mcabber) on remote computers without the need to keep the SSH session always open.
screen
screen irssi
<Ctrl-A><Ctrl-D>
(Tmux: <Ctrl-B><Ctrl-D>
)screen -r
screen -r -d
screen -x
tmux
is similar, but rewritten from scratch, colorful by default, misses some features, offers others.autossh -t computer 'screen -RD'
and you will be connected to your shell again if the network connection is good again.sshfs computer:/home/myaccount home-on-computer cd home-on-computer
command="foobar" ssh-rsa AAAAB3Nza…
calls "foobar" and only "foobar" upon every login with this keyfrom="computer" ssh-rsa AAAAB3Nza…
allows access with this key only from the host "computer".no-{agent,port,X11}-forwarding ssh-rsa AAAAB3Nza…
disallows misc. forwardings.no-pty ssh-rsa AAAAB3Nza…
disallows the allocation of a pseudo terminal.-D
and hence giving me the idea to this talk