axel@beckert.ch
https://axel.beckert.ch/
host/port
-Syntax (für IPv6 gedacht) wurde
entfernt. Es gibt die [2001:db8::1]:22
-Syntax
und 2001:db8::1/22
sieht eher nach CIDR-Notation
aus.
-J
(ProxyJump) auch bei scp
und sftp
./etc/services
) angegeben
werden.ssh-keygen
schreibt private
Schlüssel per Default im OpenSSH-eigenen Format,
unterstützt von allen OpenSSH-Versionen seit 2014.PermitListen
-Direktive
für authorized_keys
.GNU Screen bzw. Tmux erlauben u.a. Shells und andere Text-Modus-Programme (z.B. mutt, irssi, mcabber) auf anderen Rechnern weiterlaufen zu lassen ohne die ssh-Verbindung dorthin permanent offen zu halten.
screen
screen irssi
<Ctrl-A><Ctrl-D>
screen -r
screen -r -d
screen -x
tmux
ist moderner, bunter, leicht anders, kann tlw. mehr, tlw. wenigerautossh -t rechner 'screen -RD'
und man hat seine Shell wieder, sobald die Verbindung wieder steht.sshfs rechner:/home/meinkonto home-auf-rechner cd home-auf-rechner
ssh-audit: Zeigt alle möglichen Metadaten eines SSH-Servers an und bewertet sie.
$ ssh-audit somehost # general (gen) banner: SSH-2.0-OpenSSH_7.4p1 Debian-10+deb9u6 (gen) software: OpenSSH 7.4p1 (gen) compatibility: OpenSSH 7.3+, Dropbear SSH 2016.73+ (gen) compression: enabled (zlib@openssh.com) # key exchange algorithms (kex) curve25519-sha256 -- [warn] unknown algorithm (kex) curve25519-sha256@libssh.org -- [info] available since OpenSSH 6.5, Dropbear SSH 2013.62 (kex) ecdh-sha2-nistp256 -- [fail] using weak elliptic curves `- [info] available since OpenSSH 5.7, Dropbear SSH 2013.62 (kex) ecdh-sha2-nistp384 -- [fail] using weak elliptic curves `- [info] available since OpenSSH 5.7, Dropbear SSH 2013.62 (kex) ecdh-sha2-nistp521 -- [fail] using weak elliptic curves `- [info] available since OpenSSH 5.7, Dropbear SSH 2013.62 (kex) diffie-hellman-group-exchange-sha256 -- [warn] using custom size modulus (possibly weak) `- [info] available since OpenSSH 4.4 (kex) diffie-hellman-group16-sha512 -- [info] available since OpenSSH 7.3, Dropbear SSH 2016.73 (kex) diffie-hellman-group18-sha512 -- [info] available since OpenSSH 7.3 (kex) diffie-hellman-group14-sha256 -- [info] available since OpenSSH 7.3, Dropbear SSH 2016.73 (kex) diffie-hellman-group14-sha1 -- [warn] using weak hashing algorithm `- [info] available since OpenSSH 3.9, Dropbear SSH 0.53 # host-key algorithms (key) ssh-rsa -- [info] available since OpenSSH 2.5.0, Dropbear SSH 0.28 (key) rsa-sha2-512 -- [info] available since OpenSSH 7.2 (key) rsa-sha2-256 -- [info] available since OpenSSH 7.2 (key) ecdsa-sha2-nistp256 -- [fail] using weak elliptic curves `- [warn] using weak random number generator could reveal the key `- [info] available since OpenSSH 5.7, Dropbear SSH 2013.62 (key) ssh-ed25519 -- [info] available since OpenSSH 6.5 # encryption algorithms (ciphers) (enc) chacha20-poly1305@openssh.com -- [info] available since OpenSSH 6.5 `- [info] default cipher since OpenSSH 6.9. (enc) aes128-ctr -- [info] available since OpenSSH 3.7, Dropbear SSH 0.52 (enc) aes192-ctr -- [info] available since OpenSSH 3.7 (enc) aes256-ctr -- [info] available since OpenSSH 3.7, Dropbear SSH 0.52 (enc) aes128-gcm@openssh.com -- [info] available since OpenSSH 6.2 (enc) aes256-gcm@openssh.com -- [info] available since OpenSSH 6.2 # message authentication code algorithms (mac) umac-64-etm@openssh.com -- [warn] using small 64-bit tag size `- [info] available since OpenSSH 6.2 (mac) umac-128-etm@openssh.com -- [info] available since OpenSSH 6.2 (mac) hmac-sha2-256-etm@openssh.com -- [info] available since OpenSSH 6.2 (mac) hmac-sha2-512-etm@openssh.com -- [info] available since OpenSSH 6.2 (mac) hmac-sha1-etm@openssh.com -- [warn] using weak hashing algorithm `- [info] available since OpenSSH 6.2 (mac) umac-64@openssh.com -- [warn] using encrypt-and-MAC mode `- [warn] using small 64-bit tag size `- [info] available since OpenSSH 4.7 (mac) umac-128@openssh.com -- [warn] using encrypt-and-MAC mode `- [info] available since OpenSSH 6.2 (mac) hmac-sha2-256 -- [warn] using encrypt-and-MAC mode `- [info] available since OpenSSH 5.9, Dropbear SSH 2013.56 (mac) hmac-sha2-512 -- [warn] using encrypt-and-MAC mode `- [info] available since OpenSSH 5.9, Dropbear SSH 2013.56 (mac) hmac-sha1 -- [warn] using encrypt-and-MAC mode `- [warn] using weak hashing algorithm `- [info] available since OpenSSH 2.1.0, Dropbear SSH 0.28 # algorithm recommendations (for OpenSSH 7.4) (rec) -diffie-hellman-group14-sha1 -- kex algorithm to remove (rec) -diffie-hellman-group-exchange-sha256 -- kex algorithm to remove (rec) -ecdh-sha2-nistp256 -- kex algorithm to remove (rec) -ecdh-sha2-nistp384 -- kex algorithm to remove (rec) -ecdh-sha2-nistp521 -- kex algorithm to remove (rec) -ecdsa-sha2-nistp256 -- key algorithm to remove (rec) -hmac-sha1 -- mac algorithm to remove (rec) -hmac-sha2-256 -- mac algorithm to remove (rec) -hmac-sha2-512 -- mac algorithm to remove (rec) -umac-64@openssh.com -- mac algorithm to remove (rec) -umac-128@openssh.com -- mac algorithm to remove (rec) -hmac-sha1-etm@openssh.com -- mac algorithm to remove (rec) -umac-64-etm@openssh.com -- mac algorithm to remove
lshd
)Identität eines SSH-Servers mit SSH-Host-Keys verifizieren
ssh-keygen -l -f /etc/ssh/ssh_host_<algorithmus>_key.pub
(fügt .pub
automatisch hinzu, falls weggelassen):
$ 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
(Neben ~/.ssh/known_hosts
wird per Default auch in
~/.ssh/known_hosts2
geschaut. Wie praktisch! ;-)PLUGIN=curl EXIT_IGNORE='6 7 28' URL='https://db.debian.org/debian_known_hosts'
SSH-Host-Keys per DNS verifizieren — DNSSEC empfohlen
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 c-cactus.deuxchevaux.org IN SSHFP 3 1 2de9449a6917145f0839a5b6d41c30cb2685bb1d c-cactus.deuxchevaux.org IN SSHFP 3 2 8a459888de5d7ed2c6d88be79282038fe2cde417e34fc9655fdb4fc91a249b46
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)?
Mit SSH-Schlüsseln arbeiten
ssh-keygen
(Nur in Ausnahmen ohne Passphrase!)ssh-copy-id
(schreibt Key(s) in ~/.ssh/authorized_keys
remote)eval `ssh-agent`
(Kann auch durch Xsession gestartet worden sein.)ssh-add
ssh-add -l
(List fingerprints) /
ssh-add -L
(List public key parameters)ssh anderer.rechner -t -A ssh-add
(Schlüssel von anderem Rechner in den Key-Agent laden.)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
Dateien mit SSH übertragen
$ scp datei meinkonto@rechner:verzeichnis/ datei 100% 337 0.3KB/s 00:00
$ sftp meinkonto@rechner Connecting to rechner... sftp> ls datei1 datei2 sftp> get datei1 Fetching /home/meinkonto/datei1 to datei1 /home/abe/datei1 100% 337 0.3KB/s 00:00 sftp> lls datei1 datei3 sftp> put datei3 Uploading datei3 to /home/meinkonto/datei3 datei3 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 # OpenSSH ≥ 7.3 Host myhomeserver ProxyJump myhomegateway
ssh -J company-jumphost,team-jumphost server
(OpenSSH ≥ 7.3)
$EDITOR ~/.ssh/config
Host host-with-picky-firewall ControlMaster autoask ControlPath ~/.ssh-master-%l-%h-%p-%r
rsh
auf.rsh
oft symbolischer Link auf ssh
falls rsh nicht installiertset tunnel="ssh -q imap.example.org /etc/rimapd"
)inbox-path={imap.example.org/user=meinkonto/secure}INBOX folder-collections=Mail {imap.example.org/user=meinkonto/secure}[] rsh-open-timeout=0 ssh-path=/usr/bin/ssh
ssh
kann automatisch den passenden Tunnel
einrichten und $DISPLAY
passend setzen. Braucht
xauth
remote im Suchpfad.-X
oder ForwardX11 yes
-Y
oder ForwardX11 yes
+ ForwardX11Trusted yes
(Details in ssh_config(5)
)-x
oder ForwardX11 no
-g
zu freischalten des Zugriffs von überall.ssh -L 8080:proxy:8080 heimrouter
(Proxy zuhause von aussen nutzen)ssh -R 8000:localhost:8001 firmenrechner
(Firmenrechner Zugriff auf lokalen Webserver geben)ssh -R 8000:localhost:8001 -g firmenrechner
(Allen Firmenrechnern Zugriff auf lokalen Webserver geben)ssh als SOCKS-Proxy nutzen
ssh -D 1080 rechner
und
localhost:1080
als SOCKS-Proxy in Browser,
E-Mail-Programm, sonstigem Programm oder mit tsocks
angeben<Enter>~
passiert nix?~~
ergibt eine Tilde~.
beendet die Verbindung sofort~<Ctrl-Z>
stoppt die SSH (Wieder weiterlaufen lassen: fg
)~&
schiebt die SSH in den Hintergrund nach Ausloggen falls noch Tunnel genutzt werden.~?
zeigt die Hilfecommand="blafasel" ssh-rsa AAAAB3Nza…
führt bei jedem Login mit diesem Schlüssel "blafasel" ausfrom="rechner" ssh-rsa AAAAB3Nza…
erlaubt Zugriff mit diesem Schlüssel nur von "rechner" aus.no-{agent,port,X11}-forwarding ssh-rsa AAAAB3Nza…
verbietet diverses Weiterleiten.no-pty ssh-rsa AAAAB3Nza…
verbietet Pseudo-Terminals.no-port-forwarding,no-X11-forwarding,no-agent-forwarding,no-pty,command="~/sync </dev/null >/dev/null 2>&1 &" ssh-rsa AAAAB3Nza…
$SSH_ORIGINAL_COMMAND
, Feedback via STDIN/STDOUT:
no-port-forwarding,no-X11-forwarding,no-agent-forwarding,no-pty,command="~/ftpsync" ssh-rsa AAAAB3Nza…
-D
und
damit der Idee zum Vortrag