ssh
Différences
Ci-dessous, les différences entre deux révisions de la page.
Les deux révisions précédentesRévision précédente | |||
ssh [2019/10/09 14:36] – [Redirection de port] simon | ssh [Date inconnue] (Version actuelle) – supprimée - modification externe (Date inconnue) 127.0.0.1 | ||
---|---|---|---|
Ligne 1: | Ligne 1: | ||
- | ====== La commande " | ||
- | La page de [[man de ssh]]. | ||
- | |||
- | ===== Générer une clé SSH ===== | ||
- | < | ||
- | <code bash> | ||
- | simon@localhost: | ||
- | Generating public/ | ||
- | </ | ||
- | </ | ||
- | |||
- | Générer une clé [[https:// | ||
- | <code bash> | ||
- | $ ssh-keygen -t ed25519 | ||
- | Generating public/ | ||
- | Enter file in which to save the key (/ | ||
- | Enter passphrase (empty for no passphrase): | ||
- | Enter same passphrase again: | ||
- | Your identification has been saved in / | ||
- | Your public key has been saved in / | ||
- | The key fingerprint is: | ||
- | SHA256: | ||
- | The key's randomart image is: | ||
- | +--[ED25519 256]--+ | ||
- | | oo..o=o@@X | ||
- | |.. .= BoBoB | | ||
- | | o + * +.B . | | ||
- | | + + o = o | | ||
- | | = o E . | | ||
- | | . = . + | | ||
- | | . . | ||
- | | | ||
- | | | | ||
- | +----[SHA256]-----+ | ||
- | </ | ||
- | |||
- | On ajoute la nouvelle clé au " | ||
- | <code bash> | ||
- | simon@localhost: | ||
- | Could not open a connection to your authentication agent. | ||
- | |||
- | simon@localhost: | ||
- | |||
- | simon@localhost: | ||
- | Enter passphrase for .ssh/ | ||
- | Identity added: .ssh/ | ||
- | </ | ||
- | |||
- | On envoie à présent la clé sur le serveur : | ||
- | <code bash> | ||
- | simon@localhost: | ||
- | / | ||
- | / | ||
- | LOGIN@NOM-DE-DOMAINE.COM' | ||
- | |||
- | Number of key(s) added: 1 | ||
- | |||
- | Now try logging into the machine, with: " | ||
- | and check to make sure that only the key(s) you wanted were added. | ||
- | </ | ||
- | |||
- | Plus qu'à se connecter, sans rentrer de code cette fois : | ||
- | <code bash> | ||
- | simon@localhost: | ||
- | LOGIN@HOST~$ | ||
- | </ | ||
- | |||
- | ==== 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. | ||
- | </ | ||
- | [[https:// | ||
- | |||
- | ===== 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 / | ||
- | (...) | ||
- | PasswordAuthentication no | ||
- | ChallengeResponseAuthentication no | ||
- | UsePAM no | ||
- | (...) | ||
- | </ | ||
- | |||
- | Redémarrez le service SSH. | ||
- | <code bash> | ||
- | # systemctl restart ssh | ||
- | </ | ||
- | |||
- | (source : [[https:// | ||
- | |||
- | ===== 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: | ||
- | </ | ||
- | * 10145 : Port d' | ||
- | * 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:// | ||
- | |||
- | ==== Redirection de port à travers un "Jump Host" ==== | ||
- | Nous voulons nous connecter à une base de données MySQL derrière un "Jump Host"/" | ||
- | |||
- | 3 machines donc : | ||
- | * La machine locale | ||
- | * Le Jump Host : 192.168.1.10 | ||
- | * Le serveur qui héberge la base de données : 192.168.1.20(: | ||
- | |||
- | <code bash> | ||
- | $ ssh -L 3306: | ||
- | |||
- | $ mysql -u USER-DB -p -h 127.0.0.1 | ||
- | mysql> | ||
- | </ | ||
- | |||
- | ===== Ignorer la vérification du host ===== | ||
- | Ce n'est pas forcément une bonne idée... Mais on a pas toujours le choix (par exemple pour lancer une commande ssh depuis un script...). | ||
- | |||
- | <code bash> | ||
- | $ ssh -o UserKnownHostsFile=/ | ||
- | </ | ||
- | |||
- | (source : [[https:// | ||
- | |||
- | ===== Problèmes rencontrés ===== | ||
- | ==== Problèmes de droits ==== | ||
- | <code bash> | ||
- | $ ssh hostname | ||
- | Bad owner or permissions on / | ||
- | </ | ||
- | |||
- | Il faut avoir les bonnes permissions sur le fichier '' | ||
- | <code bash> | ||
- | $ ls -alh ~/ | ||
- | -rwxrwxrwx. 1 user user 324 30 mar 2016 / | ||
- | </ | ||
- | |||
- | Solution : | ||
- | <code bash> | ||
- | $ chmod 600 ~/ | ||
- | </ | ||
- | |||
- | Après : | ||
- | <code bash> | ||
- | $ ls -alh ~/ | ||
- | -rw-------. 1 user user 324 30 mar 2016 / | ||
- | </ | ||
- | |||
- | ===== Exemples et astuces ===== | ||
- | |||
- | * [[Redirection de l' | ||
- | * [[Reverse SSH]], pour intervenir à distance sur un ordinateur derrière un NAT. | ||
- | * [[http:// | ||
- | * [[https:// |
ssh.1570631808.txt.gz · Dernière modification : 2020/08/09 12:59 (modification externe)