一 創建秘鑰
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 you@HOST
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 you@1.1.1.1
如果秘鑰不在以上路徑,有兩種方法:
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