开启ssh------解决远程登录失败的问题

时间:2022-08-31 10:12:12

有的时候别人可能登录不上你的电脑或者无法登录到服务器,最可能出现的问题就是ssh出现了问题。


[root@zong_pc zong]# /etc/init.d/sshd status      //在linux下查看ssh的状态
openssh-daemon (pid 2309) 正在运行...
[root@zong_pc zong]#

[root@zong_pc zong]# /etc/init.d/sshd start       //若是ssh处于关闭状态,则可以手动开启服务
 

[root@zong_pc /]# /etc/init.d/sshd close
用法: /etc/init.d/sshd {start|stop|restart|reload|force-reload|condrestart|try-restart|status}
[root@zong_pc /]# /etc/init.d/sshd stop
停止 sshd: [确定]
[root@zong_pc /]# /etc/init.d/sshd status
openssh-daemon 已停
[root@zong_pc /]# /etc/init.d/sshd start
正在启动 sshd: [确定]
[root@zong_pc /]# /etc/init.d/sshd stop
停止 sshd: [确定]
[root@zong_pc /]#

可以直接按以下方法操作:

vim /etc/ssh/sshd_config        
截的部分代码:
 39 # Authentication:
40
41 #LoginGraceTime 2m
42 PermitRootLogin no          
43 #StrictModes yes
44 #MaxAuthTries 6
45 #MaxSessions 10
46

若PermitRootLogin后的参数为no,则会出现这样的提示:
[root@zong_pc ssh]# ssh 192.168.40.223
ssh: connect to host 192.168.40.223 port 22: No route to host




具体步骤总结::
因此,只需将其后的参数改为yes就可以了。PermitRootLogin  yes
修改完成后,
先打开ssh:/etc/init.d/sshd start
然后ssh需要重新启动 /etc/init.d/sshd restart
 

当然,也可能出现下面这种情况:

[root@localhost zhangna]# ssh 192.168.40.22
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ 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
8b:d9:17:7d:97:d5:19:02:a1:27:9f:cc:b8:31:20:34.
Please contact your system administrator.
Add correct host key in /root/.ssh/known_hosts to get rid of this message.
Offending key in /root/.ssh/known_hosts:1
RSA host key for 192.168.40.22 has changed and you have requested strict checking.
Host key verification failed.
[root@localhost zhangna]# rm -rf /root/.ssh/known_hosts
 [root@localhost zhangna]# ssh 192.168.40.22
The authenticity of host '192.168.40.22 (192.168.40.22)' can't be established.
RSA key fingerprint is 8b:d9:17:7d:97:d5:19:02:a1:27:9f:cc:b8:31:20:34.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.40.22' (RSA) to the list of known hosts.
Address 192.168.40.22 maps to localhost, but this does not map back to the address - POSSIBLE BREAK-IN ATTEMPT!
root@192.168.40.22's password:
Last login: Wed Jan 13 10:46:24 2016 from 192.168.40.222
[root@localhost ~]#