关于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
接着,输入自己想要设置的密码即可

解决 Nginx SSH 登录中 `root` 账户密码验证失败的问题,可以从以下几个方面入手: ### 1. 配置文件检查 SSH配置文件通常位于 `/etc/ssh/sshd_config`。需要确认以下设置是否正确: - **PermitRootLogin**: 这个选项决定了是否允许通过 `root` 用户登录。如果该值被设为 `no` 或者其他限制性的值,则无法使用 `root` 帐号登录[^4]。 ```bash PermitRootLogin yes ``` - **PasswordAuthentication**: 如果此参数被禁用 (即设置为 no),则即使输入正确的密码也无法完成身份认证[^5]。 ```bash PasswordAuthentication yes ``` 修改完成后记得重启 sshd 服务来应用更改: ```bash sudo systemctl restart sshd ``` ### 2. 密码策略合规性 有时由于系统安全政策的原因,可能要求用户的密码满足一定的复杂度标准才能成功登陆。可以尝试重置 root 密码并确保新密码符合这些规定。 执行命令以更新 root 密码: ```bash sudo passwd root ``` 当提示创建新密码时,请遵循推荐的安全实践设定强健的密码组合[^6]。 ### 3. SELinux/AppArmor 影响评估 某些 Linux 发行版默认启用了强制访问控制机制如 SELinux 或 AppArmor ,它们可能会阻止特定类型的连接请求包括远程 shell 访问。对于 CentOS/RHEL 系统来说特别需要注意 SELinux 设置的影响;而对于 Ubuntu 则更多关注于 AppArmor 行为约束情况下的表现差异[^7]。 可以通过临时关闭 selinux 来测试其影响效果(仅用于诊断目的不建议长期如此操作) : ```bash setenforce 0 ``` 或者查看 apparmor 当前的状态以及日志记录寻找潜在冲突源信息: ```bash aa-status --enabled cat /var/log/kern.log | grep -i apparmor ``` 以上方法应该能够帮助定位到具体原因所在从而有效解决问题。另外提醒一下,在生产环境中尽量避免直接使用超级管理员权限进行日常运维工作以免带来不必要的风险隐患!
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值