Outils pour utilisateurs

Outils du site


ssh

La commande "ssh"

La page de man de ssh.

Générer une clé SSH

simon@localhost:~$ ssh-keygen -t rsa -b 8192
Generating public/private rsa key pair.

On ajoute la nouvelle clé au “ssh-agent” :

simon@localhost:~$ ssh-add .ssh/id_rsa
Could not open a connection to your authentication agent.
 
simon@localhost:~$ ssh-agent bash
 
simon@localhost:~$ ssh-add .ssh/id_rsa
Enter passphrase for .ssh/id_rsa: 
Identity added: .ssh/id_rsa (.ssh/id_rsa)

On envoie à présent la clé sur le serveur :

simon@localhost:~$ ssh-copy-id LOGIN@NOM-DE-DOMAINE.COM
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
LOGIN@NOM-DE-DOMAINE.COM's password: 
 
Number of key(s) added: 1
 
Now try logging into the machine, with:   "ssh 'LOGIN@NOM-DE-DOMAINE.COM'"
and check to make sure that only the key(s) you wanted were added.

Plus qu'à se connecter, sans rentrer de code cette fois :

simon@localhost:~$ ssh LOGIN@NOM-DE-DOMAINE.COM
LOGIN@HOST~$

Changer la passphrase d'une clé SSH

$ cd .ssh/
$ ssh-keygen -f id_rsa -p
Enter old passphrase: 
Key has comment 'rsa w/o comment'
Enter new passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved with the new passphrase.

source (cyberciti.biz)

Problèmes rencontrés

Problèmes de droits

$ ssh hostname
Bad owner or permissions on /home/user/.ssh/config

Il faut avoir les bonnes permissions sur le fichier ~/.ssh/config. Avant :

$ ls -alh ~/.ssh/config 
-rwxrwxrwx. 1 user user 324 30 mar  2016 /home/user/.ssh/config

Solution :

$ chmod 600 ~/.ssh/config

Après :

$ ls -alh ~/.ssh/config 
-rw-------. 1 user user 324 30 mar  2016 /home/user/.ssh/config

Exemples et astuces

ssh.txt · Dernière modification: 2017/04/19 20:07 par simon