Google cloud创建实例后ssh无法连接

佬们遇到一个奇怪的问题, 我在Google cloud上创建了实例发现有的实例可以在本地ssh登录, 但是有的实例就不行

创建实例后我修改sshd_config, 把PermitRootLogin yes和PasswordAuthentication yes都改成了yes, 使用重启了ssh服务也是用passwd设置了密码,但是登录的时候一直提示Permission denied (publickey).


重装系统

@“[未知用户]”#p27756 就是Google cloud新创建的实例、新的系统

重启一下 sshd

@“[未知用户]”#p27761 sshd也重启了/etc/init.d/ssh restart

@“[未知用户]”#p27762 你查看一下 sshd的状态 </s>systemctl status sshd<e> 看下有没有报错

@“[未知用户]”#p27763 麻烦大佬帮我看一下, 感谢大佬, 我看了一下65319这个端口的是我自己的IP, 剩下的不是我的IP

`● ssh.service - OpenBSD Secure Shell server

Loaded: loaded (/lib/systemd/system/ssh.service; enabled; vendor preset: enabled)

Active: active (running) since Mon 2024-05-13 06:41:16 UTC; 4min 7s ago

Docs: man:sshd(8)

man:sshd_config(5)

Process: 1556 ExecStartPre=/usr/sbin/sshd -t (code=exited, status=0/SUCCESS)

Main PID: 1557 (sshd)

Tasks: 1 (limit: 2342)

Memory: 1.0M

CGroup: /system.slice/ssh.service

└─1557 sshd: /usr/sbin/sshd -D [listener] 0 of 10-100 startups

May 13 06:41:16 instance-20240513-063428 systemd[1]: Starting OpenBSD Secure Shell server...
May 13 06:41:16 instance-20240513-063428 sshd[1557]: Server listening on 0.0.0.0 port 22.
May 13 06:41:16 instance-20240513-063428 sshd[1557]: Server listening on :: port 22.
May 13 06:41:16 instance-20240513-063428 systemd[1]: Started OpenBSD Secure Shell server.
May 13 06:41:47 instance-20240513-063428 sshd[1564]: Connection closed by authenticating user root xxx.xxx.xxx.xxx port 65319 [preauth]
May 13 06:45:19 instance-20240513-063428 sshd[1590]: Invalid user unknown from xxx.xxx.xxx.xxx port 53895
May 13 06:45:19 instance-20240513-063428 sshd[1590]: Connection closed by invalid user unknown xxx.xxx.xxx.xxx port 53895 [preauth]
May 13 06:45:22 instance-20240513-063428 sshd[1592]: Invalid user supervisor from xxx.xxx.xxx.xxx port 40901
May 13 06:45:23 instance-20240513-063428 sshd[1592]: Connection closed by invalid user supervisor xxx.xxx.xxx.xxx port 40901 [preauth]`

防火墙我也确认了是关闭的状态

sshd服务正常的,可能还是证书方式登录,没有改成功吧。

@“[未知用户]”#p27770 :huaji12:哭死了, 我再研究研究, 感谢大佬

@“pixel”#p27778

编辑下面文件

vim /etc/ssh/sshd_config

KbdInteractiveAuthentication no 改为yes

重启sshd
systemctl restart sshd

不出意外应该是好了

@“[未知用户]”#p27781 大佬KbdInteractiveAuthentication这个没有找到, 我要自己添加一条么? 系统是ubuntu20.04

@“pixel”#p27782 新增这个属性试试,如果还有问题只能重装系统了

@“[未知用户]”#p27784 :huaji12:只能这样了么

@“[未知用户]”#p27784 佬我添加了那个属性后再连接 提示内容变了Permission denied (publickey,keyboard-interactive), 多了一个keyboard-interactive


经过反复多次实验发现只要创建的是ubuntu20.04就有概率无法使用ssh连接, 换成其他操作系统或其他版本则没有问题. 不折腾了, 再次感谢之前各位大佬的指点.

您遇到的问题很可能是因为虽然您修改了sshd_config来允许root登录和密码认证,但是Google Cloud可能仍然默认启用了仅通过公钥进行SSH身份验证的策略。此外,即使您修改了配置,也可能有其他的安全措施或策略阻止您使用密码登录。

@“[未知用户]”#p29348 感觉大佬说的有道理、不知道哪里阻止了. 换个系统和版本就可以了

看到Google我之前也注册一个,不过谷歌的速度很快