1.使用ssh-keygen生成私鑰和公鑰
命令以下:nginx
ssh-keygen -t rsa
例子:算法
fdipzone@ubuntu:~$ ssh-keygen -t rsa Generating public/private rsa key pair. Enter file in which to save the key (/home/fdipzone/.ssh/id_rsa): 這裏輸入要生成的文件名 Enter passphrase (empty for no passphrase): 這裏輸入密碼 Enter same passphrase again: 這裏重複輸入密碼 Your identification has been saved in /home/fdipzone/.ssh/id_rsa. Your public key has been saved in /home/fdipzone/.ssh/id_rsa.pub. The key fingerprint is: f2:76:c3:6b:26:10:14:fc:43:e0:0c:4d:51:c9:a2:b0 fdipzone@ubuntu The key's randomart image is: +--[ RSA 2048]----+ | .+=*.. | | . += + | | o oo+ | | E . . o | | ..S. | | .o . | | .o + | | ...oo | | +. | +-----------------+
參數 -t rsa 表示使用rsa算法進行加密,執行後,會在/home/當前用戶/.ssh目錄下找到id_rsa(私鑰)和id_rsa.pub(公鑰)shell
fdipzone@ubuntu:~$ ls -lt ~/.ssh 總用量 12 -rw------- 1 fdipzone fdipzone 1679 2015-08-07 00:28 id_rsa -rw-r--r-- 1 fdipzone fdipzone 397 2015-08-07 00:28 id_rsa.pub
也可使用 dsa 加密算法進行加密,命令以下:ubuntu
ssh-keygen -t dsa
2.設定客戶端鏈接使用的ssh私鑰和公鑰
vim /etc/ssh/ssh_config
找到vim
# IdentityFile ~/.ssh/identity # IdentityFile ~/.ssh/id_rsa # IdentityFile ~/.ssh/id_dsa
把前面#去掉,而後在 IdentityFile 後填寫你用來執行ssh時所用的密鑰ruby