1、设置root密码
如果root未设置过密码,先以普通账号登录,然后输入以下命令来修改root密码:
sudo passwd root
2、开启root远程登录
- 切换root用户
- 修改sshd_config文件,将PermitRootLogin的值改成yes,并保存
-
修改sshd_config文件,将PasswordAuthentication的值改成yes,并保存
-
修改sshd_config文件,将PubkeyAuthentication的值改成yes,并保存
-
修改认证文件/root/.ssh/authorized_keys
vi /root/.ssh/authorized_keys
删除如下内容
no-port-forwarding,no-agent-forwarding,no-X11-forwarding,command="echo 'Please login as the user "centos" rather than the user "root".';echo;sleep 10"
-
重启ssh服务
# service sshd restart systemctl restart sshd.service
3、测试root远程登录成功
4、快捷脚步
sed -i 's/^#?PermitRootLogin yes./PermitRootLogin yes/g' /etc/ssh/sshd_config;
sed -i 's/^#?PasswordAuthentication yes./PasswordAuthentication yes/g' /etc/ssh/sshd_config;
sed -i 's/^#?PubkeyAuthentication yes./PubkeyAuthentication yes/g' /etc/ssh/sshd_config;
echo "" > /root/.ssh/authorized_keys;
service sshd restart;