方法1:
创建实例时候添加命令
在创建实例的时候,一定要输入SSH密钥
如果你怕那个比较麻烦!那么利用 cloud-init脚本来开启root账号密码登录!
#!/bin/bash
echo root:你的密码 |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

方法2:
使用密钥登录系统以后
执行如下命令
sudo -s
passwd 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
重启sshd服务