Outils pour utilisateurs

Outils du site


ssh

Différences

Ci-dessous, les différences entre deux révisions de la page.

Lien vers cette vue comparative

Les deux révisions précédentesRévision précédente
Prochaine révision
Révision précédente
ssh [2018/09/03 13:27] simonssh [Date inconnue] (Version actuelle) – supprimée - modification externe (Date inconnue) 127.0.0.1
Ligne 1: Ligne 1:
-====== La commande "ssh" ====== 
  
-La page de [[man de ssh]]. 
- 
-===== Générer une clé SSH ===== 
-<hidden>Générer une clé RSA (obsolète) : 
-<code bash> 
-simon@localhost:~$ ssh-keygen -t rsa -b 8192 
-Generating public/private rsa key pair. 
-</code> 
-</hidden> 
- 
-Générer une clé [[https://fr.wikipedia.org/wiki/EdDSA|EdDSA]] (implémentation ed25519) : 
-<code bash> 
-$ ssh-keygen -t ed25519 
-Generating public/private ed25519 key pair. 
-Enter file in which to save the key (/home/simon/.ssh/id_ed25519):  
-Enter passphrase (empty for no passphrase):  
-Enter same passphrase again:  
-Your identification has been saved in /home/simon/.ssh/id_ed25519. 
-Your public key has been saved in /home/simon/.ssh/id_ed25519.pub. 
-The key fingerprint is: 
-SHA256:imFAWJVVN0MP8MJbwXgw4CWLcqWbZzQ1elGE8Tnjbgw simon@deb 
-The key's randomart image is: 
-+--[ED25519 256]--+ 
-| oo..o=o@@X      | 
-|..  .= BoBoB     | 
-|  o + * +.B .    | 
-|   + + o = o     | 
-|    = o E .      | 
-|   . = . +       | 
-|    . .        | 
-|               | 
-|                 | 
-+----[SHA256]-----+ 
-</code> 
- 
-On ajoute la nouvelle clé au "ssh-agent" : 
-<code bash> 
-simon@localhost:~$ ssh-add .ssh/id_ed25519 
-Could not open a connection to your authentication agent. 
- 
-simon@localhost:~$ ssh-agent bash 
- 
-simon@localhost:~$ ssh-add .ssh/id_ed25519 
-Enter passphrase for .ssh/id_ed25519:  
-Identity added: .ssh/id_ed25519 (.ssh/id_ed25519) 
-</code> 
- 
-On envoie à présent la clé sur le serveur : 
-<code bash> 
-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. 
-</code> 
- 
-Plus qu'à se connecter, sans rentrer de code cette fois : 
-<code bash> 
-simon@localhost:~$ ssh LOGIN@NOM-DE-DOMAINE.COM 
-LOGIN@HOST~$ 
-</code> 
- 
-==== Changer la passphrase d'une clé SSH ==== 
- 
-<code bash> 
-$ 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. 
-</code> 
-[[https://www.cyberciti.biz/faq/howto-ssh-changing-passphrase/|source (cyberciti.biz)]] 
- 
-===== Empêcher la connexion au serveur par mot de passe ===== 
-Maintenant qu'on a une clé en ed25519, on peut empêché la connexion par mot de passe. 
- 
-Éditez le fichier de configuration suivant : 
-<code bash> 
-# vim /etc/ssh/sshd_config 
-(...) 
-PasswordAuthentication no 
-ChallengeResponseAuthentication no 
-UsePAM no 
-(...) 
-</code> 
- 
-Redémarrez le service SSH. 
-<code bash> 
-# systemctl restart ssh 
-</code> 
- 
-(source : [[https://www.security-helpzone.com/2018/07/29/ssh-autoriser-uniquement-les-connexions-avec-cle-privee/|https://www.security-helpzone.com/2018/07/29/ssh-autoriser-uniquement-les-connexions-avec-cle-privee/]] ) 
- 
-===== Redirection de port ===== 
-Pour accéder à une ressource distante (par exemple, un site web en développement qui tourne en local sur un serveur distant) : 
-<code bash> 
-$ ssh -L 4001:localhost:4000 user@192.168.1.44 -p 10145 
-</code> 
-  * 10145 : Port d'écoute du serveur ssh (optionnel si on a laissé le port à "22") 
-  * 4001 : Port local sur lequel on veut rediriger le port du serveur 
-  * 4000 : Port distant où tourne le service qu'on peut récupérer en local 
- 
-(source : [[https://nikolov.fr/2018/08/redirection-de-port-avec-ssh/|https://nikolov.fr/2018/08/redirection-de-port-avec-ssh/]] 
- 
-===== Problèmes rencontrés ===== 
-==== Problèmes de droits ==== 
-<code bash> 
-$ ssh hostname 
-Bad owner or permissions on /home/user/.ssh/config 
-</code> 
- 
-Il faut avoir les bonnes permissions sur le fichier ''~/.ssh/config''. Avant : 
-<code bash> 
-$ ls -alh ~/.ssh/config  
--rwxrwxrwx. 1 user user 324 30 mar  2016 /home/user/.ssh/config 
-</code> 
- 
-Solution : 
-<code bash> 
-$ chmod 600 ~/.ssh/config 
-</code> 
- 
-Après : 
-<code bash> 
-$ ls -alh ~/.ssh/config  
--rw-------. 1 user user 324 30 mar  2016 /home/user/.ssh/config 
-</code> 
- 
-===== Exemples et astuces ===== 
- 
-  * [[Redirection de l'affichage via X]] 
-  * [[Reverse SSH]], pour intervenir à distance sur un ordinateur derrière un NAT. 
-  * [[http://links.simonlefort.be/?gmvu_g|Streaming avec mplayer]] 
ssh.1535981265.txt.gz · Dernière modification : 2020/08/09 12:59 (modification externe)