设置 SSH 无密码登录
本文介绍如何在 Windows 10 中设置SSH无密码通过密钥登陆LINUX。
设置密钥登陆,需要有一个公钥和一个私钥,公钥存放在服务器上,私钥存放在本地主机上
本地主机:win10 服务器:ubuntu18.04 运行环境:PowerShell
现在开始配置密钥登陆
- 配置密钥对参见win10配置密钥对
- 复制公钥到服务器
cat ~/.ssh/id_rsa.pub | ssh remote_username@server_ip_address "mkdir -p ~/.ssh && chmod 700 ~/.ssh && cat >> ~/.ssh/authorized_keys && chmod 600 ~/.ssh/authorized_keys"
- 使用 SSH 密钥登录服务器
ssh remote_username@server_ip_address
- 禁用 SSH 密码身份验证
- 使用 SSH 密钥登录远程服务器,以具有 sudo 权限的用户或 root 身份:
ssh sudo_user@server_ip_address
- 修改 /etc/ssh/sshd_config配置文件
/etc/ssh/sshd_config PasswordAuthentication no ChallengeResponseAuthentication no UsePAM no
完成后,保存文件并重新启动SSH服务
执行该命令sudo systemctl restart ssh