执行
ssh-keygen -t rsa
命令行生成公钥、密钥,需要交互输入的直接回车键
Nelson:~ Nelson$ ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/Users/freegeek/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /Users/freegeek/.ssh/id_rsa.
Your public key has been saved in /Users/freegeek/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:8apTQO4+0lrrLaAOj+rDNEvBn4RobR6NK4dLpz1B0ck [email protected]
The key's randomart image is:
+---[RSA 2048]----+
| o . |
| . E. |
|o o +o . |
|.= B .o o |
|. O +. .S . |
| B O. . .. |
|* X..+... |
| X.o..*+ |
|=o+ o+++. |
+----[SHA256]-----+
复制代码
此时
.ssh
目录会多出
id_rsa
、
id_rsa.pub
两个文件.
将公钥文件复制到远程设备中
# ssh-copy-id [email protected]
复制代码
此时再次通过
ssh
连接远程设备就不需要密码
Nelson:~ Nelson$ ssh [email protected]
Nelson-iPad:~ root#
复制代码