SSH Secure Shell Client 连接linux失败

2019年02月20日 09:40:15 光利繁华的背后 阅读数:172

注:小问号是ubuntu16.04,在安装ssh-server。(sudo apt-get install openssh-server)报错解决以后,使用Quick Connet链接时出现下面对话框的提示。

sudo apt-get install openssh-server安装过程中出现错误信息:

root@ubuntu:/etc/init.d# pe -e | grep ssh   //查看有没有显示服务器  ,!!!!!!!!命令写错了应该是ps -e | grep ssh
pe: command not found                        //没有这个命令

root@ubuntu:/etc/init.d# ps -e | grep ssh   //如果安装了ssh,就显示下面的内容,有ssh的文字。
 36214 ?        00:00:00 sshd
 36215 ?        00:00:00 sshd
如果执行命令ps -e | grep ssh后只有ssh-agent,说明ssh-server还没有启动,需要执行命令:/etc/init.d/ssh start,如果看到sshd的字符内容,那就说明ssh-server已经启动了。

 

root@ubuntu:/etc/init.d# sudo ufw disable   //关闭防火墙

root@ubuntu:/etc/init.d# sudo /etc/init.d/ssh start  //重启ssh服务器
[....] Starting ssh (via systemctl): ssh.serviceJob for ssh.service failed because the control process exited with error code. See "systemctl status ssh.service" and "journalctl -xe" for details.
 failed!

 

首先执行:sudo apt-get update

 

更新完毕后执行

sudo apt-get install openssh-client     (记不清楚了不知道是这一步还是上一步虚拟机还要自动重新启动,这样给自己查看重                                                                 启以前在虚拟机屏幕上的信息就没有了,所以在执行这两步的时候记着要把屏幕上的需                                                                  要的信息赋值或截图下来便于查找对照。)

sudo apt-get install openssh-server

再执行重启命令:service sshd start或service ssh restart  和systemctl start    sshd    #开启服务和 systemctl restart    sshd            #重启服务

如果执行service sshd start命令是出现:

root@ubuntu:/etc/init.d# service sshd start
Job for ssh.service failed because the control process exited with error code. See "systemctl status ssh.service" and "journalctl -xe" for details.
然后执行命令:systemctl status ssh.service

root@ubuntu:/etc/init.d# systemctl status ssh.service
● ssh.service - OpenBSD Secure Shell server
   Loaded: loaded (/lib/systemd/system/ssh.service; enabled; vendor preset: enab
   Active: failed (Result: start-limit-hit) since Thu 2019-04-25 19:52:07 PDT; 2
  Process: 35811 ExecStartPre=/usr/sbin/sshd -t (code=exited, status=255)
 Main PID: 1141 (code=exited, status=0/SUCCESS)

Apr 25 19:52:07 ubuntu systemd[1]: ssh.service: Control process exited, code=exi
Apr 25 19:52:07 ubuntu systemd[1]: Failed to start OpenBSD Secure Shell server.
Apr 25 19:52:07 ubuntu systemd[1]: ssh.service: Unit entered failed state.
Apr 25 19:52:07 ubuntu systemd[1]: ssh.service: Failed with result 'exit-code'.
Apr 25 19:52:07 ubuntu systemd[1]: ssh.service: Service hold-off time over, sche
Apr 25 19:52:07 ubuntu systemd[1]: Stopped OpenBSD Secure Shell server.
Apr 25 19:52:07 ubuntu systemd[1]: ssh.service: Start request repeated too quick
Apr 25 19:52:07 ubuntu systemd[1]: Failed to start OpenBSD Secure Shell server.

执行journalctl -xe“”

root@ubuntu:/etc/init.d# journalctl -xe
-- Unit ssh.service has failed.
-- 
-- The result is failed.
Apr 25 19:52:07 ubuntu systemd[1]: ssh.service: Unit entered failed state.
Apr 25 19:52:07 ubuntu systemd[1]: ssh.service: Failed with result 'exit-code'.
Apr 25 19:52:07 ubuntu systemd[1]: ssh.service: Service hold-off time over, sche
Apr 25 19:52:07 ubuntu systemd[1]: Stopped OpenBSD Secure Shell server.
-- Subject: Unit ssh.service has finished shutting down
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
-- 
-- Unit ssh.service has finished shutting down.
Apr 25 19:52:07 ubuntu systemd[1]: ssh.service: Start request repeated too quick
Apr 25 19:52:07 ubuntu systemd[1]: Failed to start OpenBSD Secure Shell server.
-- Subject: Unit ssh.service has failed
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
 

root@ubuntu:/etc/init.d# sudo /usr/sbin/sshd -T   //查看错误代码的位置
/etc/ssh/sshd_config: line 29: Bad configuration option: PermitRoorLogin
/etc/ssh/sshd_config: terminating, 1 bad configuration options
 

然后执行root@ubuntu:/etc/init.d# vi /etc/ssh/sshd_config打开文件发现:

PermitRoorLogin yes  这一行显示白色的,细心发现PermitRoorLogin写错了,应该是PermitRootLogin

更改后执行:root@ubuntu:/etc/init.d# sudo /usr/sbin/sshd -T

显示:root@ubuntu:/etc/init.d# sudo /usr/sbin/sshd -T
port 22
protocol 2
addressfamily any
listenaddress [::]:22
listenaddress 0.0.0.0:22
usepam yes
serverkeybits 1024
logingracetime 120
keyregenerationinterval 3600
x11displayoffset 10
maxauthtries 6
maxsessions 10
clientaliveinterval 0
clientalivecountmax 3
streamlocalbindmask 0177
permitrootlogin yes
ignorerhosts yes
ignoreuserknownhosts no
rhostsrsaauthentication no
hostbasedauthentication no

执行root@ubuntu:/etc/init.d# systemctl status ssh.service  //显示服务器ssh的状态

● ssh.service - OpenBSD Secure Shell server
   Loaded: loaded (/lib/systemd/system/ssh.service; enabled; vendor preset: enab
   Active: failed (Result: start-limit-hit) since Thu 2019-04-25 19:52:07 PDT; 4
  Process: 35811 ExecStartPre=/usr/sbin/sshd -t (code=exited, status=255)
 Main PID: 1141 (code=exited, status=0/SUCCESS)

Apr 25 19:52:07 ubuntu systemd[1]: ssh.service: Control process exited, code=exi
Apr 25 19:52:07 ubuntu systemd[1]: Failed to start OpenBSD Secure Shell server.
Apr 25 19:52:07 ubuntu systemd[1]: ssh.service: Unit entered failed state.
Apr 25 19:52:07 ubuntu systemd[1]: ssh.service: Failed with result 'exit-code'.
Apr 25 19:52:07 ubuntu systemd[1]: ssh.service: Service hold-off time over, sch

 

执行root@ubuntu:/etc/init.d# systemctl start sshd  //启动ssh 服务显示:

ssh.service - OpenBSD Secure Shell server
   Loaded: loaded (/lib/systemd/system/ssh.service; enabled; vendor preset: enab
   Active: active (running) since Thu 2019-04-25 21:35:32 PDT; 10s ago
  Process: 36092 ExecStartPre=/usr/sbin/sshd -t (code=exited, status=0/SUCCESS)
 Main PID: 36094 (sshd)
   CGroup: /system.slice/ssh.service
           └─36094 /usr/sbin/sshd -D

Apr 25 21:35:32 ubuntu systemd[1]: Starting OpenBSD Secure Shell server...
Apr 25 21:35:32 ubuntu sshd[36094]: Server listening on 0.0.0.0 port 22.
Apr 25 21:35:32 ubuntu sshd[36094]: Server listening on :: port 22.
Apr 25 21:35:32 ubuntu systemd[1]: Started OpenBSD Secure Shell server.
 

root@ubuntu:/etc/init.d# service ssh restart  //启动ssh
root@ubuntu:/etc/init.d# ps -e | grep ssh   //查看ssh有没有启动,发现下面内容中已有ssh字符,说明已经启动
 36214 ?        00:00:00 sshd
 36215 ?        00:00:00 sshd
root@ubuntu:/etc/init.d# ^C
root@ubuntu:/etc/init.d# ps -s | grep ssh  //查看ssh 的状态
    0  36882 0000000000000000 0000000000000000 0000000000000000 0000000180000000 S+   pts/18     0:00 grep --color=auto ssh
 

至此ssh服务器已经安装成功了。下面就是使用SSH Secure Shell登录虚拟机上的ssh服务器了。

 

.linux中服务的管理 
    systemctl    动作    服务
    systemctl start    sshd    #开启服务
    systemctl stop    sshd    #停止服务
    systemctl status    sshd            #查看服务状态
    systemctl restart    sshd            #重启服务
    systemctl reload    sshd            #让服务从新加载配置
    systemctl enable    sshd            #设定服务开启启动
    systemctl disable    sshd    #设定服务开机不启动

systemctl list-unit-files    #查看系统中所有服务的开机启动状态
    systemctl list-units    #查看系统中所有开启的服务
    systemctl set-default graphical.target    #开机时开启图形
    systemctl set-default multi-user.targe    #开机时不开图形

 

 

系统服务的控制
 1)systemd
  系统初始化程序,系统开始的第一个进程,pid为1

 2)systemctl 命令
 systemctl list-units          ##列出当前系统服务的状态
 systemctl list-unit-files     ##列出服务的开机状态
 systemctl status sshd         ##查看指定服务的状态
 systemctl stop sshd            ##关闭指定服务
 systemctl start sshd           ##开启指定服务
 systemctl restart sshd        ##从新启动服务
 systemctl enable sshd         ##设定指定服务开机开启
 systemctl disable sshd        ##设定指定服务开机关闭
 systemctl reload sshd         ##使指定服务从新加载配置
 systemctl list-dependencies sshd   ##查看指定服务的倚赖关系
 systemctl mask sshd           ##冻结指定服务
 systemctl unmask sshd         ##启用服务
 systemctl set-default multi-user.target    ##开机不开启图形
 systemctl set-default graphical.target ##开机启动图形
 setterm                   ##文本界面设定color

 3)服务状态
 systemctl status     服务名称

 loaded            ##系统服务已经初始化完成,加载过配置
 active(running)     ##正有一个或多个程序正在系统中执行,
               #vsftpd 就是这种模式

 atcive(exited)      ##仅执行一次就正常結束的服务,
               #目前并没有任何程序在系統中执行

 atcive(waiting)     ##正在执行当中,
               #不过还再等待其他的事件才能继续处理

 inactive          ##服务关闭
 enbaled           ##服务开机启动
 disabled          ##服务开机不自启
 static            ##服务开机启动项不可被管理
 failed            ##系统配置错误

 

但在执行sudo apt-get install openssh-server出现Package has no installation candidate,解决方法如下:

#  apt-get install    //这句可能写错了,应该是sudo apt-get install openssh-server
Reading package lists... Done
Building dependency tree... Done
Package aptitude is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source
E: Package has no installation candidate


解决方法如下:
# sudo apt-get update  //可能提示失败,执行第二步
# sudo apt-get upgrade   //可能提示失败,执行第三步吧
# sudo apt-get install   //再执行就成功了,这里执行apt-get install  ssh


如果还不行请换163的源,参考http://mirrors.163.com/.help/ubuntu.html
 

 

 

 

 

 

在使用SSH Secure Shell登录虚拟机上的ssh服务器时出现下面的错误警示框:

 

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/Z_HUALIN/article/details/87775358

则修改以下配置文件(该段落引自 https://segmentfault.com/a/1190000005709819) 
解决Server responded “Algorithm negotiation failed”的问题

# 修改ssh的配置文件
vim /etc/ssh/sshd_config

# 允许root用户登录,将“PermitRootLogin without-password”更改为
PermitRootLogin yes

# 在配置文件中添加如下内容(除了第三条的最后一个是灰色加紫色,其他的是蓝色,如果是灰色说明不对!)
Ciphers aes128-cbc,aes192-cbc,aes256-cbc,aes128-ctr,aes192-ctr,aes256-ctr,3des-cbc,arcfour128,arcfour256,arcfour,blowfish-cbc,cast128-cbc

MACs hmac-md5,hmac-sha1,umac-64@openssh.com,hmac-ripemd160,hmac-sha1-96,hmac-md5-96

KexAlgorithms diffie-hellman-group1-sha1,diffie-hellman-group14-sha1,diffie-hellman-group-exchange-sha1,diffie-hellman-group-exchange-sha256,ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,diffie-hellman-group1-sha1,curve25519-sha256@libssh.org

(该段落引自 https://segmentfault.com/a/1190000005709819)

小问号将上面的内容复制到文件:/etc/ssh/sshd_config中的尾部,复制粘贴后代码的显示与上面说的(除了第三条的最后一个是灰色加紫色,其他的是蓝色,如果是灰色说明不对!)不对,我的情况是这样:截图:有三个地方是灰色加紫色。没有去管它,直接执行重启命令systemctl start sshd
,重启以后可以连接上了。

 

 

 

下面这4幅图是SSH链接过程中的截图:

 

 

 

 

 

 

 

 

 

 

重启ssh服务
service ssh restart

重新连接即可。