Commande ssh¶
Se connecter à un serveur par un autre port que 22:¶
bruno@macbook-pro:~$ ssh bruno@192.168.1.7 -p 42666
bruno@192.168.1.7's password:
bruno@DS916:/var/services/homes/bruno $
Fixer le message WARNING: UNPROTECTED PRIVATE KEY FILE!¶
On réinitilalise les permissions des clés:
bruno@macbook-pro:~$ sudo chmod 600 ~/.ssh/id_rsa
bruno@macbook-pro:~$ sudo chmod 600 ~/.ssh/id_rsa
Si cela ne suffit pas:
bruno@macbook-pro:~$ sudo chmod 600 ~/.ssh/known_hosts
bruno@macbook-pro:~$ sudo chmod 755 ~/.ssh
Copier un fichier:¶
macbook-pro:~ bruno$ ssh root@192.168.1.8 "cat prefs.tar.gz"> prefs.tar.gz
Exécuter une (ou plusieurs) commande sur un serveur distant:¶
macbook-pro:~ bruno$ ssh root@192.168.1.8 hostname
DiskStation
bruno@SilverBook:~$ ssh -p34987 bruno@xxxxxxx.synology.me 'hostname ; uptime'
bruno@xxxxxxx.synology.me's password:
DS916
07:56:40 up 2 days, 19:50, 0 users, load average: 1.13, 1.15, 1.14
bruno@SilverBook:~$ ssh -p34987 bruno@xxxxxxx.synology.me << EOF
> uname -a
> lscpu | grep "^CPU(s)"
> grep -i memtotal /proc/meminfo
> EOF
Pseudo-terminal will not be allocated because stdin is not a terminal.
bruno@clicclac.synology.me's password:
Linux DS916 3.10.102 #15266 SMP Mon Mar 26 15:12:32 CST 2018 x86_64 GNU/Linux synology_braswell_916+
/bin/bash: line 2: lscpu: command not found
MemTotal: 1963472 kB
Exécuter un script distant sur un serveur distant:¶
$ ssh -p34987 bruno@xxxxxxx.synology.me ./test.sh
bruno@clicclac.synology.me's password:
09:55:03 up 2 days, 21:49, 0 users, load average: 1.14, 1.25, 1.23
DS916
Si le script nécessite un sudo:
$ ssh -t bruno@maboiteverte.fr ./purge_server.sh
# sinon erreur:
# sudo: no tty present and no askpass program specified
Exécuter un script local sur un serveur distant:¶
bruno@SilverBook:~$ ssh -p34987 bruno@xxxxxxx.synology.me 'bash -s' < test.sh
bruno@xxxxxxx.synology.me's password:
toto
Mode verbose¶
bruno@macbook-pro:~$ ssh -vvv dsm916
OpenSSH_6.9p1, LibreSSL 2.1.8
debug1: Reading configuration data /Users/bruno/.ssh/config
debug1: /Users/bruno/.ssh/config line 3: Applying options for dsm916
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 20: Applying options for *
debug1: /etc/ssh/ssh_config line 102: Applying options for *
debug2: ssh_connect: needpriv 0
debug1: Connecting to 192.168.1.7 [192.168.1.7] port 22.
debug1: Connection established.
debug1: identity file /Users/bruno/.ssh/id_dsa type 2
.../...
bruno@DS916:/var/services/homes/bruno $
Dernière mise à jour:
September 16, 2018