SSH 免密登录 Windows 与 Ubuntu 服务器
本文主要记录了客户端与 Windows 服务器和 Ubuntu 服务器的 SSH 免密登录配置方法。
SSH 免密登录 Windows 服务器
开启 OpenSSH 服务
1
Start-Service sshd # PowerShell
添加客户端的公钥到 Windows 服务器的
~\.ssh\authorized_keys
文件中修改 OpenSSH 服务的配置文件
C:\ProgramData\ssh\sshd_config
,需要使用管理员权限打开1
2
3
4
5
6
7
8确保以下3条没有被注释
PubkeyAuthentication yes # enable public key authentication
AuthorizedKeysFile .ssh/authorized_keys # path of authorized_keys
PasswordAuthentication no # disable password login
确保以下2条有注释掉
Match Group administrators
AuthorizedKeysFile __PROGRAMDATA__/ssh/administrators_authorized_keys
- 重启 OpenSSH 服务
1
Restart-Service sshd # PowerShell
- 在客户端测试免密登录
1
ssh username@hostname
SSH 免密登录 Ubuntu 服务器
在 Ubuntu 服务器上安装 OpenSSH 服务
1
2
3
4
5ssh # check if OpenSSH is installed
sudo apt-get install openssh-server # install OpenSSH
sudo ufw allow ssh # allow OpenSSH through the firewall
sudo systemctl start ssh # start OpenSSH
sudo systemctl status ssh # check the status of OpenSSH在客户端生成 SSH 密钥对 Ref
将客户端的公钥添加到 Ubuntu 服务器的
~/.ssh/authorized_keys
文件中修改 Ubuntu 服务器的 SSH 配置文件
sudo nvim /etc/ssh/sshd_config
1
2PubkeyAuthentication yes # enable public key authentication
PasswordAuthentication no # disable password login重启 OpenSSH 服务
1
sudo systemctl restart ssh
在客户端测试免密登录
1
ssh username@hostname
SSH 免密登录 Windows 与 Ubuntu 服务器