Table des matières
- 2026:
- 2025:
4 billet(s) pour juillet 2026
| Procédure simple augmentation de la SWAP | 2026/07/17 15:49 | Jean-Baptiste |
| Exemple git clone avec Ansible | 2026/07/16 14:47 | Jean-Baptiste |
| Windows exe - Comparaison de fichiers binaires | 2026/07/16 10:25 | Jean-Baptiste |
| Pb git | 2026/07/01 17:36 | Jean-Baptiste |
SSH
https://github.com/FiloSottile/whosthere
Voir
Voir man ssh_config
~/.ssh/config ou /etc/ssh/ssh_config
~/.ssh/config
Host *
ServerAliveInterval 300
ServerAliveCountMax 3
ControlMaster auto
ControlPath ~/.ssh/master-%r@%h:%p
ControlPersist 4h
EscapeChar ~
Host srvlnxvm1
User root
HostName srvlnxvm1
ProxyCommand ssh -W %h:%p srvlnxrbd
Host srvlnxdir1
HostName srvlnxdir1
LocalForward 1389 127.0.0.1:389
LocalForward 1636 127.0.0.1:636
# ExitOnForwardFailure yes
Host srvlnxvm2 192.168.22.42
Hostname srvlnxvm2
ProxyCommand ssh -W %h:%p srvlnxrbd
Host *
User root
Host gtw
Hostname 192.168.22.78
PubkeyAuthentication=no
Port 6322
#lftp sftp://user:pass@gtw
Host 192.168.22.63
Hostname 192.168.22.63
ProxyCommand ssh -W %h:%p srvlnxrbd
ForwardAgent yes
#ProxyCommand ssh srvlnxrbd nc %h %p
Host test1
User root
Hostname 192.168.2.41
IdentityFile ~/.ssh/clefs/id_rsa_test1
Pour débugger ssh_config :
ssh -G user@somehost.example.com
Notes
/etc/ssh/sshd_not_to_be_run
Réutiliser la connexion existante au lieu de refaire une nouvelle connexion. Accélère
Source http://www.linuxjournal.com/content/speed-multiple-ssh-connections-same-server
~/.ssh/config
Host * ControlMaster auto ControlPath ~/.ssh/master-%r@%h:%p ControlPersist 4h
Pour cette connexion (temporairement) ne pas utiliser l'authentification par clef
ssh -o "PreferredAuthentications keyboard-interactive,password" user@192.168.1.18
SSH Escape Sequences (aka Kill Dead SSH Sessions)
~/.ssh/config
Host *
EscapeChar ~
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.
Sécurité
ssh-keygen -G moduli-3072.candidates -b 3072
Voir : https://entropux.net/article/openssh-moduli/
/etc/ssh/moduli
Pb déconnexion
Déconnexion SSH au bout de 30 secondes avec Write Failed: broken pipe
Doublon d'adresses IP
Autres
ssh force password / Ne pas utiliser la clef mais demander le mot de passe
ssh -o PreferredAuthentications=password -o PubkeyAuthentication=no 192.168.1.22
A l'inverse, options SSH sans mot de passe, pour script
ssh -o PasswordAuthentication=no -o ChallengeResponseAuthentication=no -o PreferredAuthentications=publickey -o StrictHostKeyChecking=no -o ConnectTimeout=2 -o BatchMode=yes 192.168.1.22
SSH-Agent
ssh à Jean
Connexion avec ssh-agent pour Connexion SSH, passphrase demandée qu'une seule fois
Lister les clefs connues
$ ssh-add -l Could not open a connection to your authentication agent.
Communication avec l'agent impossible ⇒ soit il n'est pas chargé, soit il y a un problème.
Pour forcer sa fermeture
$ ssh-agent -k SSH_AGENT_PID not set, cannot kill agent
Activation de l'agent ssh
$ eval $(ssh-agent -s) Agent pid 10449
Pour lister les clefs chargées
$ ssh-add -l The agent has no identities.
Pour charger la clef par défaut
$ ssh-add Enter passphrase for /home/jibe/.ssh/id_dsa: Identity added: /home/jibe/.ssh/id_dsa (/home/jibe/.ssh/id_dsa)
!! Plus aucune passphrase vous sera demandé pour vous connecter !
Plus vérouiller votre ssh-agent (plus de connexion sans passphrase)
$ ssh-add -x Enter lock password: Again: Agent locked.
Pour déverrouiller
$ ssh-add -X Enter lock password: Agent unlocked.
On regardes les clefs chargées
$ ssh-add -l 1024 c7:7e:ab:f1:f9:ed:a4:d0:81:ee:6b:d1:3f:b4:4f:ca /home/jibe/.ssh/id_dsa (DSA)
Ajout d'une 2em clef :
$ ssh-add ~/.ssh/id_rsa_clef2 Identity added: /home/jibe/.ssh/id_rsa_clef2 (rsa w/o comment)
On regarde de nouveau les clefs chargées
$ ssh-add -l 1024 c7:7e:ab:f1:f9:ed:a4:d0:81:ee:6b:d1:3f:b4:4f:ca /home/jibe/.ssh/id_dsa (DSA) 768 c1:8d:5a:00:23:87:c7:2f:8a:e3:9d:88:15:9d:eb:4c rsa w/o comment (RSA)
Faire oublier toutes les clefs
$ ssh-add -D All identities removed.
Fermer ssh-agent
$ eval $(ssh-agent -k) Agent pid 10449 killed
Variables SSH_AGENT_PID et SSH_AUTH_SOCK pas exportées
~/.bashrc
if [[ -z $SSH_AGENT_PID ]] then SSH_AGENT_PID="$(pgrep -n ssh-agent)" SSH_AUTH_SOCK="$(ls -1rt /tmp/ssh-*/agent.* | tail -1)" export SSH_AGENT_PID export SSH_AUTH_SOCK fi
On tente de lister les clefs connues
$ ssh-add -l Could not open a connection to your authentication agent
Pour ne saisir qu'une seule fois la passe-phrase à l'ouverture de la session console
~/.bashrc
ssh-add -l >/dev/null if [[ $? -eq 1 ]] then ssh-add fi
Exemple complète de conf
~/.bash_rc
pgrep ssh-agent >/dev/null if [[ $? -eq 1 ]] then eval $(ssh-agent -s) fi if [[ -z $SSH_AGENT_PID ]] then SSH_AGENT_PID="$(pgrep -n ssh-agent)" SSH_AUTH_SOCK="$(ls -1rt /tmp/ssh-*/agent.* | tail -1)" export SSH_AGENT_PID export SSH_AUTH_SOCK fi ssh-add -l >/dev/null if [[ $? -eq 1 ]] then ssh-add fi
Tunnel SSH proxy socks
Voir aussi : sshuttle
http://artisan.karma-lab.net/faire-passer-trafic-tunnel-ssh
ssh -D 1080 jb@mon_serveur
Notes clefs SSH
Création de la paire de clefs
Création de la paire de clefs par script
if [ ! -e ~/.ssh/id_rsa ] then ssh-keygen -q -N "" < /dev/zero fi
SSH Générer une clef publique à partir d'une clef privée
Create Public Key from Private
ssh-keygen -y -f ~/.ssh/id_rsa > ~/.ssh/id_rsa.pub
Emprunte (Fingerprint) de la clef SSH
ssh-keygen -lf ~/.ssh/id_rsa.pub ssh-keygen -E md5 -lf ~/.ssh/id_rsa.pub
Ou
ssh-add ~/.ssh/id_rsa_jbl2 ssh-add -l ssh-add -L | ssh-keygen -E md5 -lf -
Pour une clef pem générée via AWS (à partir de la clef privée)
openssl pkcs8 -in /home/jibe/.ssh/id_rsa_jbl2 -nocrypt -topk8 -outform DER | openssl sha1 -c
Pb
Pb userauth_pubkey: key type ssh-dss not in PubkeyAcceptedKeyTypes
Voir
/var/log/auth.log
Jan 23 22:40:37 server1 sshd[26567]: userauth_pubkey: key type ssh-dss not in PubkeyAcceptedKeyTypes [preauth]
/etc/ssh/sshd_config
PubkeyAcceptedKeyTypes=+ssh-dss
ssh-keygen -t ecdsa #ssh-keygen -t ecdsa -b 521
Err no mutual signature algorithm
$ ssh -v old-rhel5 ... debug1: send_pubkey_test: no mutual signature algorithm ...
Solution (contournement)
PubkeyAcceptedKeyTypes +ssh-rsa
~/.ssh/config
Host old-rhel5 Hostname 192.168.1.20 KexAlgorithms +diffie-hellman-group1-sha1,diffie-hellman-group14-sha1 HostKeyAlgorithms +ssh-rsa PubkeyAcceptedKeyTypes +ssh-rsa
ssh -R binds to 127.0.0.1 only on remote
Voir aussi :
A tester : GatewayPorts clientspecified
ssh -R "61027:db1.acme.local:61027" admin@app1.acme.local
Le binding n'est que sur 127.0.0.1
# ss -tlnp | grep 610
LISTEN 0 128 127.0.0.1:61027 0.0.0.0:* users:(("sshd",pid=3983617,fd=15))
Essayons
ssh -g -R "0.0.0.0:61027:db1.acme.local:61027" admin@app1.acme.local
Ca ne marche pas
Idem avec -o GatewayPorts=true
Sur notre machine en écoute sur 127.0.0.1:61027
ssh -g -L 61028:0.0.0.0:61027 localhost
Mais comme nous n'avons pas la clef SSH sur la cible nous faisons :
ssh -A -t admin@app1.acme.local ssh -g -L 61028:0.0.0.0:61027 admin@localhost
Et voilà :
# ss -tlnp | grep 610
LISTEN 0 128 127.0.0.1:61027 0.0.0.0:* users:(("sshd",pid=3983617,fd=15))
LISTEN 0 128 0.0.0.0:61028 0.0.0.0:* users:(("ssh",pid=3987404,fd=6))
Autres
Erreurs après un certain temps lors de la connexion
$ ssh -R "61027:db1.acme.local:61027" admin@app1.acme.local connect_to db1.acme.local port 61027: failed. connect_to db1.acme.local port 61027: failed. connect_to db1.acme.local port 61027: failed. connect_to db1.acme.local port 61027: failed.
