ssh无法登录问题的解决办法
- 打开服务器控制台,输入
ps -e|grep ssh
,查看是否有sshd - 如果没有,ubuntu使用
apt-get install openssh-server
,centos使用yum install openssh-server
- 修改ssh配置文件
vim /etc/ssh/sshd_config
,将PasswordAuthentication
设为yes
,PermitRootLogin
设为yes
/etc/init.d/ssh restart
,重启ssh- 如果使用命令行登录,登录命令为
ssh username@IP
ssh定时掉线问题
部分云服务器会设置一定时间不操作,ssh掉线的功能。去除这个功能建议服务端和客户端都进行设置。
服务端
修改ssh配置文件vim /etc/ssh/sshd_config
,找到
ClientAliveInterval 60 #服务端主动向客户端请求响应的间隔
ClientAliveCountMax 999 #服务器发出请求后客户端没有响应的次数达到一定值就自动断开
将ClientAliveCountMax
改为999
,基本可保证使用期间不断开。重启ssh服务。
客户端
如果使用mobaxterm,点击settings
图标,选择SSH
选项卡,在SSH keepalive
上打钩即可。
如果使用linux终端,那么需要编辑/etc/ssh/ssh_config
或~/.ssh/config
,找到下面的配置项更改后重启。
TCPKeepAlive yes #TCP长连接
ServerAliveInterval 15 #客户端主动向服务端请求响应的间隔
ServerAliveCountMax 999 #服务器发出请求后客户端没有响应的次数达到一定值就自动断开
StrictHostKeyChecking no #不进行主机公钥确认
ForwardAgent yes #可进行ssh密钥代理转发
Compression yes #可进行压缩数据传输
IPQoS lowdelay throughput #IP服务低延时吞吐,防止出现packet_write_wait错误
参考网站
解决无法通过SSH远程登录Ubuntu
SSH连接总是定期断掉的解决办法
ssh StrictHostKeyChecking
ssh密钥代理转发(ssh agent forwarding)
ssh设置长连接
SSH服务:packet_write_wait: Connection to 67.218.143.160 port 22: Broken pipe错误处理