1. 客户端生成公钥


# 一路回车就行
root@node130:~# 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:7e50VJXJc9ixQvEziR0ry00ka5uIbZrK7yJQH0YK+7w root@node130
The key's randomart image is:
+---[RSA 2048]----+
| +o*=|
| . . . O*B|
| o o *.Xo|
| . o o .o +.O o|
| + o S..+.= . |
| . o . .+. |
| . . oo . |
| E...o . |
| .o++o |
+----[SHA256]-----+


2. 复制公钥到对应服务器


root@node130:~/.ssh# ssh-copy-id -i ~/.ssh/id_rsa.pub  root@10.172.200.139
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"
The authenticity of host '10.172.200.139 (10.172.200.139)' can't be established.
ECDSA key fingerprint is SHA256:gd/XArnlj987R5oB/08R3RhoMrhzVKUvRqrl0yNXbvw.
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@10.172.200.139's password:

Number of key(s) added: 1

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


3. 查看对应服务器的授权信息


root@node131:~# cd ~/.ssh/
root@node131:~/.ssh# ls
authorized_keys id_rsa id_rsa.pub known_hosts
root@node139:~/.ssh# vim authorized_keys
# 这个是 客户端写入到服务器的 id_rsa.pub (公钥)内容。


4. 测试登录


root@node130:~# ssh root@10.172.200.139
Welcome to uos 20 GNU/Linux

* Homepage:https://www.chinauos.com/

* Bugreport:https://bbs.chinauos.com/


Last login: Sat Jun 26 11:00:00 2021 from 10.173.134.66
root@node139:~#