Please login as the user "ubuntu" rather than the user "root".

日志

1
2
Please login as the user "ubuntu" rather than the user "root".
Connection to 1.1.1.1 closed.

大概率不是 sshd_configPermitRootLogin 在限制你,而是 root 的 SSH key 被配置了一个强制执行命令(command="..."),登录后直接检查用户名并退出。

env

  • oracle cloud computer
  • ssh

解决

1. 先用ubuntu登录

1
ssh ubuntu@1.1.1.1  -i id_ed25519_mvpbag -p 2929

进去后检查:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
# 公钥的最开头通常附带信息
/root/.ssh/authorized_keys
/home/ubuntu/.ssh/authorized_keys

# root登录放开
/etc/ssh/sshd_config
...
PermitRootLogin yes

# 云厂商初始化限定非root
/etc/cloud/cloud.cfg
...
disable_root: true
...

2.复制公钥及重启ssh服务

systemctl restart ssh

# test
ssh root@1.1.1.1 

3. 你的情况像OCI Ubuntu镜像

168.138.204.162 如果是 Oracle Cloud Infrastructure 的 Ubuntu 实例,这种:

1
Please login as the user "ubuntu" rather than the user "root".

是非常典型的云镜像预置机制。

可以直接检查:

1
sudo cat /root/.ssh/authorized_keys

如果里面有:

1
command="..."

那么限制不是 PermitRootLogin,而是 SSH authorized_keys 的 forced command