关于Ubuntu ssh远程连接报错和无法root登录的解决方法

一、使用远程工具连接Ubuntu提示报错

MobaXterm v22.0 版本直接可以远程连接上(前提是sshd服务是开启的状态)
注意:须使用最新版本或较高版本的ssh远程连接工具,进行ssh连接;若使用较低版本的ssh远程连接工具,会报错,导致连接不上

情况一:

若使用secureCRT 7.0版本远程连接提示Key exchange failed. No compatible key exchange method报错:
Key exchange failed.
No compatible key exchange method. The server supports these methods: curve25519-sha256,curve25519-sha256@libssh.org,ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,diffie-hellman-group-exchange-sha256,diffie-hellman-group16-sha512,diffie-hellman-group18-sha512,diffie-hellman-group14-sha256
在这里插入图片描述

解决方法:

root@ubuntu-virtual-machine:~# apt install -y openssh-server
root@ubuntu-virtual-machine:~# service sshd start
root@ubuntu-virtual-machine:~# ps -ef |grep ssh
ubuntu      1514    1444  0 10:55 ?        00:00:00 /usr/bin/ssh-agent /usr/bin/im-launch env GNOME_SHELL_SESSION_MODE=ubuntu /usr/bin/gnome-session --systemd --session=ubuntu
root        1980       1  0 10:57 ?        00:00:01 sshd: root@pts/0
root        1982       1  0 10:57 ?        00:00:00 sshd: root@notty
root        2118    1982  0 10:57 ?        00:00:00 /usr/lib/openssh/sftp-server
root        2473       1  0 11:10 ?        00:00:00 sshd: /usr/sbin/sshd -D [listener] 0 of 10-100 startups
root        2475    2473  0 11:10 ?        00:00:00 sshd: root@pts/1
root        2608    2117  0 11:18 pts/0    00:00:00 grep --color=auto ssh
root@ubuntu-virtual-machine:~# vim /etc/ssh/sshd_config
文件内容最后添加如下:
KexAlgorithms curve25519-sha256@libssh.org,ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,diffie-hellman-group-exchange-sha256,diffie-hellman-group14-sha1,diffie-hellman-group-exchange-sha1,diffie-hellman-group1-sha1

重启sshd服务

root@ubuntu-virtual-machine:~# service sshd restart

重新连接后,还是报错;但跟之前报错不一样,请看下面情况二解决:
在这里插入图片描述

情况二:

使用secureCRT 7.0版本ssh远程连接出现如下报错:
在这里插入图片描述
使用PuTTY 0.67.00版本ssh远程连接出现如下报错:
在这里插入图片描述

解决方法:

root@glory-virtual-machine:~# apt install -y openssh-server
root@glory-virtual-machine:~# vim /etc/ssh/sshd_config

在sshd_config配置文件底部添加如下两行内容:

HostKeyAlgorithms=+ssh-rsa,ssh-dss
KexAlgorithms=+diffie-hellman-group-exchange-sha1,diffie-hellman-group14-sha1,diffie-hellman-group1-sha1

在这里插入图片描述
重启sshd服务

root@glory-virtual-machine:~# service sshd restart

再重新连接,即可连接上在这里插入图片描述

二、ubuntu开启root用户登录

  1. 编辑修改sshd_config配置文件
root@ubuntu-virtual-machine:~# vim /etc/ssh/sshd_config
文件内容添加如下:
PermitRootLogin yes

在这里插入图片描述

  1. 重新启动sshd服务
root@ubuntu-virtual-machine:~# service sshd restart
  1. 使用putty远程连接,用root用户登录,登录成功在这里插入图片描述

Tips:
新安装的Ubuntu设置root密码
    在Ubuntu里,如果用户没有设置root密码,那么它默认有一个随机密码,这个密码是可以更改的。
    如果用户已经设置了密码,那么这个密码会一直保留,直到用户再次修改它。
   
修改root密码的方法如下:
# sudo passwd root
接着,输入自己想要设置的密码即可

  • 0
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值