ssh登录不上的通常性解决方法

ssh的英文全称是Secure SHell,这是一种既能够代替telnet,又能够为ftp、pop、甚至ppp提供一个安全的"通道"。ssh有不少的参数,下面就来介绍两个比较经常使用的参数html

PermitRootLogin prohibit-password 这个参数的意思是否容许远程root登录,默认是禁止远程root密码登录,如果须要远程root登录,就须要把这个更改成yeslinux

PasswordAuthentication 这个参数是用来定义是否容许用密码登录,这个在通常的状况下是yes,固然也有no状况shell

其余的参数设置参考这篇文档安全

###通常在ssh会遇到的问题服务器

  • 提示
# ssh 172.16.81.221
ssh: connect to host 172.16.81.221 port 22: No route to host

这因为server端没有开机或是网络不通,或者是主机down了网络

  • 提示
# ssh work@172.16.81.221
ssh: connect to host 172.16.81.221 port 22: Connection refused

这是由于对方的ssh服务没有开,开启对端sever的ssh便可ssh

  • 提示
# ssh 172.16.81.221
root@172.16.81.221's password:
Permission denied, please try again.

这是因为在不输入用户名的状况下,默认是root用户登录,结果多是对端不容许root登录.tcp

  • 提示
ssh root@172.16.81.221
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED! @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!
Someone could be eavesdropping on you right now (man-in-the-middle attack)!
It is also possible that the RSA host key has just been changed.
The fingerprint for the RSA key sent by the remote host is
76:fb:b3:70:14:48:19:d6:29:f9:ba:42:46:be:fb:77.
Please contact your system administrator.
Add correct host key in /home/fante/.ssh/known_hosts to get rid of this
message.
Offending key in /home/fante/.ssh/known_hosts:68
RSA host key for 172.16.81.221 has changed and you have requested strict checking.
Host key verification failed

这是由于对端密码或是ip对应的server等其余发生改变,与当前的不一致致使的,删除~/.ssh/known_hosts的对应行,而后再登陆便可。this

  • 提示
Xshell:\> ssh 121.207.***.***
Connecting to 121.207.***.***:22...
Connection established.
To escape to local shell, press 'Ctrl+Alt+]'.
Connection closed by foreign host. 
Type `help' to learn how to use Xshell prompt.

在服务器上重启sshd服务时,有WARNNING的,可是,sshd服务是能够启动的,那么,问题可能 出如今/etc/ssh/下面文件权限不对致使的,能够找一个可使用的,而后对比一下,就能够发现其中的区别了。code

###限制登录服务器

  • 增长hosts.deny或者是hosts.allow,限制ip
    增长 /etc/hosts.deny 文件内容:
sshd:ALL

增长:/etc/hosts.allow 文件,

sshd:192.168.10.0/255.255.255.0(准许的网段)

或者是

sshd:192.168.10.1(准许的ip)

而后重启ssh服务,这两个文件是tcpd的配置文件,tcpd能够控制外部ip对本机的访问,经过他能够容许或者拒绝某个ip或者ip段的客户访问linux的某项服务。ALL匹配全部状况,EXCEPT匹配除了某些项以外的状况,PARANOID匹配你想控制的IP地址和它的域名不匹配时(域名假装)的状况。在两个配置文件有冲突时,linux 系统会先检查/etc/hosts.deny规则,再检查/etc/hosts.allow规则,若是有冲突 按/etc/hosts.allow规则处理。

  • 限制用户 须要修改/etc/sshd/sshd_config文件中增长指定的用户例如:AllowUsers user,若是有多个用户,可使用空格隔开,也可使用user@host的方法,并且,还支持user@ip/netmask的方式,如只容许192.168.1.0/24的网段使用root登录,首先,要把PermitRootLogin设为yes,注掉也不行,由于其默认值即prohibit-password,而后在最后一行上加上
AllowUsers root@192.168.1.0/24
  • 限制输入密码的次数 修改MaxAuthTries
相关文章
相关标签/搜索