SSH 完整指南
SSH 完整指南
Section titled “SSH 完整指南”SSH 配置、优化和常见问题解决方案汇总。
常见问题排查
Section titled “常见问题排查”解决 SSH 登录慢
Section titled “解决 SSH 登录慢”方法一:关闭 DNS 反向解析
Section titled “方法一:关闭 DNS 反向解析”编辑 /etc/ssh/sshd_config:
UseDNS no重启服务:
service ssh restart方法二:关闭 GSSAPI 认证
Section titled “方法二:关闭 GSSAPI 认证”编辑 /etc/ssh/ssh_config:
GSSAPIAuthentication no重启服务生效。
允许密码登录(Ubuntu 20.04+)
Section titled “允许密码登录(Ubuntu 20.04+)”新安装的 Ubuntu 默认禁用密码登录,报错:
Permission denied (publickey)编辑 /etc/ssh/sshd_config:
# 允许密码认证PasswordAuthentication yes
# 如需 root 登录PermitRootLogin yes重启 SSH 服务:
sudo systemctl restart sshd通过跳板机连接目标服务器,编辑 ~/.ssh/config:
Host jump-server HostName 192.168.0.1 User root Port 22 StrictHostKeyChecking no
Host target-server HostName 192.168.0.2 User admin Port 22 StrictHostKeyChecking no ProxyJump jump-server然后直接:
ssh target-server本地端口转发
Section titled “本地端口转发”将远程服务映射到本地端口:
# 通过 172.23.2.55 跳板机,将 172.19.2.152:3389 映射到本地 33333 端口参数说明:
-N:不执行远程命令-f:后台运行-L:本地端口转发
远程端口转发
Section titled “远程端口转发”将本地服务暴露到远程:
# 将本地 8080 端口暴露到远程服务器的 9090 端口ssh -N -f -R 9090:localhost:8080 user@remote-server