[root@localhost]# ssh-keygen
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:
SHA256:rHLydfgdfgdfgcvbcvbcvbG3GM9tosDSERPfsEW8 root@ct-dev-01
The key's randomart image is:
+---[RSA 2048]----+
|^/o. . |
|*=@=o o |
|.*+*o+ E |
|+.+ o o. |
|+o. . S |
|+. . |
|.. o.o. |
| . .=. . |
| .o .. |
+----[SHA256]-----+
В результате выполнения команды сгенерировалось 2 файла в каталоге ~/.ssh/
- id_rsa.pub — публичный ключ
- id_rsa — секретный ключ
Копируем наш публичный ключ на сервер, к которому мы будем подключаться без ввода пароля, вместо XXX IP
[root@localhost]# ssh-copy-id root@XXX.XXX.XXX.XXX
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"
/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@XXX.XXX.XXX.XXX's password:
Number of key(s) added: 1
Now try logging into the machine, with: "ssh 'root@XXX.XXX.XXX.XXX'"
and check to make sure that only the key(s) you wanted were added.
Проверяем
Или sshpass
yum install sshpass
Заходим на ssh-сервер с именем server.example.com с паролем t@uyM59bQ
sshpass -p 't@uyM59bQ' ssh username@server.example.com
Заходим на ssh-сервер с именем server.example.com с паролем t@uyM59bQ отключая проверку ключа на хосте
sshpass -p 't@uyM59bQ' ssh -o StrictHostKeyChecking=no username@server.example.com
Скачиваем директорию с файлами
/usr/bin/sshpass -p '!@hrkUU50Tt' scp -r username@ssh.host.ru:/home/host/host.ru /FILEDUMP/BackUP/