一般我们与要登陆云服务器时需要输入密码,很麻烦也不安全,因此我们就需要免密登陆了。
Step-1: 创建登录密钥
$ ssh-keygen # 执⾏此命令
# 程序输出
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa): # 确认密钥
⽂件位置 (敲回⻋)
Enter passphrase (empty for no passphrase): # 为密钥设置密码 (⽆需密
码, 直接回⻋)
Enter same passphrase again: # 确认密码 (再次回⻋)
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:WpGZKdaT3SbGlx+pNi6H5/SBNZXjk5C468y+4MeNKxs root@box
The key's randomart image is:
+---[RSA 2048]----+
| |
| . O ......|
| o X =.=ooo.|
| . . + +.oooo|
| S .+ ++ |
| o +.+ ..|
| . E+.O . |
| ..*X o . |
| o=B+ . |
+----[SHA256]-----+
Step-2: 复制公钥到远程服务器
- 本地打开 ~/.ssh/id_rsa.pub ⽂件, 复制全部⽂本内容
- ssh 登录到远程服务器, vim 打开 ~/.ssh/authorized_keys ⽂件
- 将复制的内容写⼊⽂件, 保存退出
好了,这样下次登陆时就不需要输入密码了。当然你嫌这个方法麻烦的话,还可以使用下面这种简便的方法。
ssh-copy-id -i .ssh/id_rsa 用户名@服务器域名
本文详细介绍如何通过创建SSH密钥对实现免密登录云服务器,包括生成密钥、复制公钥到远程服务器等步骤,简化日常运维操作,提升安全性。
1020

被折叠的 条评论
为什么被折叠?



