甲骨文云永久免费服务器允许root远程ssh登录

本文最后更新于 2025年10月12日 下午

甲骨文云永久免费服务器允许root远程ssh登录

虽然操作过好多次,但还是会忘记,每次都要去查,还是自己记录一遍吧

创建新的服务器

甲骨文云在不同地区的登录地址是不一样的,我的登录地址是Cloud Sign In (oracle.com)

还需要先填名字,这是外国人很奇怪的一点,记不住设置的什么名字就登不上了

在计算-实例页面选择创建实例

映像和配置选择免费的就好

保存密钥对到本地

创建成功后在 https://ping.chinaz.com/ ping一下服务器公网IP 本机也ping一下检查是否畅通 本地网络ping畅通的服务器才有意义

SSH连接

1
ssh -i <private_key> user@remote_host

默认用户名会在实例创建时显示,Ubuntu系统是ubuntu,Centos是opc

有时候本地即使ping通也很难建立ssh连接,因为ssh使用TCP协议,而ping使用的是ICMP,所以可以使用网络环境更好的其他云服务器来建立连接,私钥权限不能放开,要设置成400

1
chmod 400 <private_key>

登录成功后修改root密码

1
2
sudo -i
passwd

设置允许root远程ssh登录,修改/etc/ssh/sshd_config

1
2
3
Port 22222
PermitRootLogin yes
PasswordAuthentication yes

处理 systemd 的 ssh.socket(解决端口不生效问题),Ubuntu 中 SSH 可能由 ssh.socket 管理,需禁用该 socket 让 SSH 服务自己监听端口:

1
2
3
4
5
sudo systemctl stop ssh.socket
sudo systemctl disable ssh.socket
sudo systemctl daemon-reload
sudo systemctl restart ssh
sudo systemctl status ssh

关闭iptables服务以允许ssh端口,后续可以重新启用其他防火墙

1
2
sudo systemctl stop iptables
sudo systemctl disable iptables

如果还不生效,可以试试下面命令,有可能被地方配置覆盖了,像这里就还需要修改/etc/ssh/sshd_config.d/60-cloudimg-settings.conf,然后再重启ssh服务

1
2
3
4
5
root@cloud2:/etc/ssh# grep -R "PasswordAuthentication" /etc/ssh/sshd_config /etc/ssh/sshd_config.d/
/etc/ssh/sshd_config:PasswordAuthentication yes
/etc/ssh/sshd_config:# PasswordAuthentication. Depending on your PAM configuration,
/etc/ssh/sshd_config:# PAM authentication, then enable this but set PasswordAuthentication
/etc/ssh/sshd_config.d/60-cloudimg-settings.conf:PasswordAuthentication no

甲骨文云永久免费服务器允许root远程ssh登录
https://xinhaojin.github.io/2023/05/20/甲骨文云永久免费服务器允许root远程ssh登录/
作者
xinhaojin
发布于
2023年5月20日
许可协议