Duke Yin's Technology database

Oracle Cloud SSH使用密码登录

方法1

需要首次使用public key链接SSH

echo root:YourPasswordHere |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

YourPasswordHere 为自定义密码

第二次就可以用root + 密码登录

方法2

创建实例的时候输入cloud-init 开机脚本。

其中 123456789 是你需要设置的 root 密码。

ubuntu

#!/bin/bash
echo root:123456789 |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:123456789 |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

发布评论

评论

标注 * 的为必填项。