remote ssh

необходимо удаленно выполнить команду на другом сервере.

используем старый ssh-client
можно так.

root@mx2:/var/shell# ssh root@IP 'uptime'
The authenticity of host 'IP (IP)' can't be established.
ECDSA key fingerprint is d4:b6:bb:5d:03:c9:15:cc:7z:5f:2a:qz:hh:0d:2f:dc.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'IP' (ECDSA) to the list of known hosts.
root@IP's password:
 07:53:42 up 321 days, 22:30,  1 user,  load average: 0.02, 0.02, 0.00
root@mx2:/var/shell#


что крайне не удобно. в плане выполнения в некоторых случаях.
будем делать через ключи.

генерация ключа. генерируем на той машине, где/откуда будем соединятся.

ssh-keygen -t rsa



Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
14:***a:db:66:6d:a3 root@mx2ru
The key's randomart image is:
+---[RSA 2048]----+
|      .o.        |
|      +  .       |
|     . +.        |
|      ...        |
|       .S        |
|      .          |
| .  .. .         |
|  o= =+ +        |
| ...O*E= .       |
+-----------------+
root@mx2:~/ssh-key#


передаем ключь на удаленный сервер
root@mx2:/var/shell# ssh-copy-id IP
/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
root@IP's password:

Number of key(s) added: 1

Now try logging into the machine, with:   "ssh 'IP'"
and check to make sure that only the key(s) you wanted were added.

root@mx2:/var/shell#


если хотим без пароля, не задаем его в
Enter passphrase (empty for no passphrase):


ключ создан, передан на удаленный сервер и проверяем.
root@mx2:/var/shell# ssh root@IP 'uptime'
 07:58:29 up 321 days, 22:35,  1 user,  load average: 0.07, 0.02, 0.00
root@mx2:/var/shell#

0 комментариев

Только зарегистрированные и авторизованные пользователи могут оставлять комментарии.