WEB-DL

甲骨文云(Oracle Cloud)、谷歌云(GCP)等新开实例(VM\VPS)配置SSH+密码登录

不少云厂商默认关闭了SSH登录功能,我用过的谷歌云(GCP)、甲骨文云(Oracle cloud)、已经跑路的几个白嫖的云厂商等,GCP其实还比较简单的,可直接控制台操作改为SSH登陆(此文不详述),但甲骨文云就很蛋疼了,用户预设SSH密钥登陆较复杂,后续再配置SSH登录也是费时间,不过甲骨文云提供了启动脚本 (cloud-init)功能,即在创建实例(VM)后第一次开机自动执行启动脚本。

以甲骨文云为例,cloud-init 开机脚本在高级选项这一栏中。

cloud-init 脚本内容

下述脚本默认设置登陆用户为:root,密码为 :1234567890

适用预安装系统为 Debian / Ubuntu

#!/bin/bash
echo root:1234567890 |sudo chpasswd root
sudo sed -i 's/#PermitRootLogin prohibit-password/PermitRootLogin yes/g' /etc/ssh/sshd_config;
sudo sed -i 's/PasswordAuthentication no/PasswordAuthentication yes/g' /etc/ssh/sshd_config;
sudo service sshd restart

适用预安装系统为 Centos

#!/bin/bash
echo root:1234567890 |sudo chpasswd root
sudo sed -i 's/PermitRootLogin no/PermitRootLogin yes/g' /etc/ssh/sshd_config;
sudo sed -i 's/PasswordAuthentication no/PasswordAuthentication yes/g' /etc/ssh/sshd_config;
sudo service sshd restart

通用脚本 (适用于大部分Linux系统,但不一定有效)

#!/bin/bash
echo root:1234567890 |sudo chpasswd root
sudo sed -i 's/^#\?PermitRootLogin.*/PermitRootLogin yes/g' /etc/ssh/sshd_config;
sudo sed -i 's/^#\?PasswordAuthentication.*/PasswordAuthentication yes/g' /etc/ssh/sshd_config;
sudo service sshd restart
码字很辛苦,转载请注明来自非WEB-DL资源站《甲骨文云(Oracle Cloud)、谷歌云(GCP)等新开实例(VM\VPS)配置SSH+密码登录》

评论