# 取消注释并修改为一个高端口号(如 2022, 2222等), 为了避开自动化扫描脚本
Port 2222
# To disable tunneled clear text passwords, change to no here!
PasswordAuthentication no
PermitEmptyPasswords no
# 禁止 root 用户直接登录
PermitRootLogin no
# 启用公钥认证 (通常默认是启用的,但请确认)
PubkeyAuthentication yes
防火墙开放端口:
1
sudo ufw allow 2222
重启SSH服务
1
sudo systemctl restart sshd # 之前的连接不会中断
配置 ssh
1
2
3
4
5
Host <ip/host_name>
#HostName <host_name> # 真实 ip/host_name
Port <port>
User <user_name>
IdentityFile ~/.ssh/<file_name>