- 生成密钥
➜ .ssh ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (~/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in ~/.ssh/id_rsa.
Your public key has been saved in ~/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:ExgdQNetjvhIt7B9BXQ3tCOTSpq5HP+s3UZlQS42bKg xxxx@xxxdeMacBook-Pro.local
The key's randomart image is:
+---[RSA 2048]----+
| .+ooo . .o. |
| +. o =.+o |
| . ...++Boo.|
| *+.ooo.o|
| .SE.. o |
| +.o=. . . |
| . Bo... . |
| o + .+ .. |
| ...+.. |
+----[SHA256]-----+
- 公钥上传到服务器
scp -P 22000 ~/.ssh/id_rsa.pub username@192.168.0.141:~/.ssh/temp001
登录服务器,公钥保存为authorized_keys
cat ~/.ssh/temp001 >> ~/.ssh/authorized_keys
rm ~/.ssh/temp001
- 配置本地ssh config文件
➜ .ssh touch config
config文件内容如下
Host hdhost
HostName 192.168.0.141
Port 22000
User root
IdentityFile ~/.ssh/id_rsa
- 免密码登录
➜ .ssh ssh hdhost
Last login: Sun Jun 3 22:34:40 2018 from 192.168.0.141
Welcome to Alibaba Cloud Elastic Compute Service !
[root@izuf61kij6ti02tzbzl3pqz ~]#
网友评论