0
点赞
收藏
分享

微信扫一扫

17. SSH公钥/私钥免密登录

萨摩斯加士奇 2022-03-11 阅读 158

17.1 服务器端开启密钥登录模式

sudo vim /etc/ssh/sshd_config

# ----------------------------------------
# 是否允许 root 远程登录
PermitRootLogin yes

# 密码登录是否打开
PasswordAuthentication yes

# 开启公钥认证
RSAAuthentication yes # 这个参数可能没有 没关系
PubkeyAuthentication yes

# 存放登录用户公钥的文件位置
# 位置就是登录用户名的家目录下的 .ssh
# root 就是 /root/.ssh
# foo 就是 /home/foo/.ssh
AuthorizedKeysFile .ssh/authorized_keys
# ----------------------------------------

service sshd restart

17.2 客户端生成公私钥

ssh-keygen

此命令会在用户目录/.ssh文件夹下创建公私钥:id_rsa(私钥)、id_rsa.pub(公钥)

17.3 上传公钥到服务器

ssh-copy-id -i user/.ssh/id_rsa.pub user@ip
# 或使用scp上传

17.4 将公钥写入到授权文件中

cat >>~/.ssh/authorized_keys<id_rsa.pub

举报

相关推荐

0 条评论