[root@kehuji ~]# ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Created directory '/root/.ssh'.
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:3Wv4KZmgFhs5dBqoS/1RzsX2xs5R/CB80a1tPfVhvO8 root@kehuji
The key's randomart image is:
+---[RSA 2048]----+
| ...|
| .++|
| . . . ..+*|
| . o o.+.o *o=|
| o . OSo.o.+ +o|
| o . B + .=. o|
| . . . B ..*o. . |
| . = +oo. E|
| . .o |
+----[SHA256]-----+
将公钥复制到远程主机上
[root@kehuji ~]# cd .ssh/
[root@kehuji .ssh]# ls
id_rsa id_rsa.pub
[root@kehuji .ssh]# ssh-copy-id -i id_rsa.pub root@192.168.194.129
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "id_rsa.pub"
The authenticity of host '192.168.194.129 (192.168.194.129)' can't be established.
ECDSA key fingerprint is SHA256:iYay6JB/dzmh28KVizE/kWaQsikP5hAmeH7hKkFRfts.
ECDSA key fingerprint is MD5:0a:d2:3d:59:98:3b:7e:37:3f:be:98:7d:65:de:0c:3d.
Are you sure you want to continue connecting (yes/no)? yes
/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@192.168.194.129's password:
Number of key(s) added: 1
Now try logging into the machine, with: "ssh 'root@192.168.194.129'"
and check to make sure that only the key(s) you wanted were added.
远程连接服务器
[root@kehuji .ssh]# ssh root@192.168.194.129
Last login: Tue Oct 22 14:10:01 2019 from 192.168.194.1
[root@service ~]#
使用scp方法连接
创建公钥-私钥对
[root@kehuji ~]# 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:
SHA256:LSe8hoP2IXRIoCRhMQ0W2BWCitIvofKtIwntjBEkcbk root@kehuji
The key's randomart image is:
+---[RSA 2048]----+
|=&Ooo. |
|O+++ |
|*. .. |
|= E. . . . |
|.+ oo . S o |
|= o..o . = |
|oB o+ + o |
|+ =..o + |
| ..o . |
+----[SHA256]-----+
手动配置ssh创建公钥-私钥对(客户机)[root@kehuji ~]# ssh-keygen -t rsaGenerating public/private rsa key pair.Enter file in which to save the key (/root/.ssh/id_rsa): Created directory '/root/.ssh'.Enter passphr...