SSH

Escape sequences

1
~# ~?
Supported escape sequences:
 ~.   - terminate connection (and any multiplexed sessions)
 ~B   - send a BREAK to the remote system
 ~C   - open a command line
 ~R   - request rekey
 ~V/v - decrease/increase verbosity (LogLevel)
 ~^Z  - suspend ssh
 ~#   - list forwarded connections
 ~&   - background ssh (when waiting for connections to terminate)
 ~?   - this message
 ~~   - send the escape character by typing it twice
(Note that escapes are only recognized immediately after newline.)

restrict ssh acces

1
~# grep AllowUsers /etc/ssh/sshd_config
AllowUsers root@93.14.29.25 jerem none

use keepalive

1
ssh -o ServerAliveInterval=5 -o ServerAliveCountMax=1 10.0.0.1

ssh tunnel

  • local tunnel

-L : local
-f : background
-n : redirect stdin > /dev/null

1
~# ssh -L 8080:localhost:80 jerem.unvrai.info -f -n
~# curl http://localhost:8080
<h1> unvrai.info welcome page </h1>
1
~# ssh -L 8080:web.unvrai.info:80 jerem.unvrai.info -f -n
~# curl http://localhost:8080
<h1> web.unvrai.info home page </h1>
  • remote tunnel
1
~# ssh -R 8080:localhost:80 jerem@unvrai.info -f -n
~# curl http://unvrai.info:8080
<h1> my local welcome page </h1>
  • SSH connection through host in the middle

    1
    ~# ssh -t reachable_host ssh unreachable_host
  • Testing remote connection to port

    1
    timeout 1 bash -c "</dev/<proto>/<host>/<port>" >/dev/null 2>&1 ; echo $?

sshfs

1
~$ mkdir /opt/doc/ansible
~$ sshfs jerem@server.fr:doc/ansible /opt/doc/ansible
1
~# grep sshfs /etc/fstab
user@machine:/répertoire/distant                /mnt/mon_rep          fuse.sshfs           port=22,user,noatime,_netdev     0 0

Forward X

1
~# grep X11 /etc/ssh/sshd_config
X11Forwarding yes
#X11DisplayOffset 10
X11UseLocalhost no

Clean keys

1
~# ssh-keygen -f "/home/jerem/.ssh/known_hosts" -R 10.0.0.10