生成祕鑰對
首先生成自己的祕鑰對,當然也可以原來有的可以跳過此步驟
使用命令:
ssh-keygen -t rsa -b 2048 -C "my email"
Generating public/private rsa key pair.
Enter file in which to save the key (/Users/dashuai/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /Users/dashuai/.ssh/id_rsa.
Your public key has been saved in /Users/dashuai/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:kxYiYIfEJhu/ct/WluV4+koqVfey7bb5u/eSCDtOTY0 [email protected]
The key's randomart image is:
+---[RSA 2048]----+
| o+.. |
|o.+o |
| * . . . |
|. . . ..o. o |
| . .S. .E . |
|. o .. .+o. |
| o . o ..=.*.. . |
| o oo=.* +.o .|
| o..o*o++o+=o|
+----[SHA256]-----+
允許服務器ssh登陸配置
首先在遠程服務器vim /etc/ssh/sshd_config確保下面三個選項是打開的
RSAAuthentication yes
PubkeyAuthentication yes
AuthorizedKeysFile .ssh/authorized_keys
保存後,centos版本使用service sshd restart 重啓ssh服務
將祕鑰對上傳至服務器
本地客戶端輸入ssh-copy-id user@host
輸入密碼。
就可以將公鑰上傳到遠程服務器的.ssh/authorized_keys
這個時候使用ssh user@host就可以不用輸入密碼直接登錄遠程服務器了
使用別名快速登錄
別名永久生效
1)在當前用戶下執行:vim ~/.bashrc 寫入alias myserver='ssh [email protected]'並保存關閉;
2)vim ~/.bash_profile加入:source ~/.bashrc使其生效
3)重啓在命令行輸入myserver就可以看到效果了