一 创建秘钥
1 Macbook
$ ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key ($HOME/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in $HOME/.ssh/id_rsa.
Your public key has been saved in $HOME/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:HqDbdb3SyrM2pPj+rrZt0F34GUjVIlDpEKuTOT473KU [email protected]
The key‘s randomart image is:
+---[RSA 2048]----+
| o+.o.. |
| ..+ . .|
| . .+ + . |
| . . + .+ o |
| . S....o o |
| o +.=o.o.o |
| . .o+=.oo |
| . ==Eo |
| +*OB+ |
+----[SHA256]-----+
$ ls -l .ssh
total 24
-rw------- 1 you staff 1876 Sep 11 23:07 id_rsa
-rw-r--r-- 1 you staff 404 Sep 11 23:07 id_rsa.pub
-rw-r--r-- 1 you staff 1046 Aug 3 10:06 known_hosts
2 Windows
2.1 XShell
2.2 SecureCRT
二 使用秘钥登录
1 Macbook
秘钥默认文件名及路径
$ vi /etc/ssh/ssh_config
# IdentityFile ~/.ssh/id_rsa
# IdentityFile ~/.ssh/id_dsa
如果秘钥在以上路径,直接登录即可
$ ssh [email protected]
如果秘钥不在以上路径,有两种方法:
1)通过-i指定秘钥路径
$ ssh -i /path/to/id_rsa you@1.1.1.1
2)修改/etc/ssh/ssh_config
2 Windows
2.1 XShell
2.2 SecureCRT
原文地址:https://www.cnblogs.com/barneywill/p/11620944.html