一、设置 root 用户密码
腾讯云 Ubuntu 系统默认禁用 root 账户。需通过以下步骤设置密码:
- 使用默认账户(如 ubuntu)登录服务器。
- 执行命令
sudo passwd root
,输入当前用户密码后设置两次 root 密码。 - 出现
password updated successfully
提示即表示成功。
二、修改 SSH 配置允许 root 登录
需调整 SSH 配置文件以启用 root 远程登录:
- 运行
sudo vim /etc/ssh/sshd_config
打开配置文件。 - 找到
PermitRootLogin
参数,修改为yes
(约第 35 行)。 - 确保
PasswordAuthentication
参数设为yes
,若不存在则手动添加。
PermitRootLogin yes PasswordAuthentication yes
三、重启 SSH 服务并验证
完成配置后需重启服务使设置生效:
- 执行
sudo service ssh restart
重启 SSH 服务。 - 关闭当前会话,使用 root 账户及密码重新登录服务器。
- 成功登录后即可执行
su
切换至 root 环境。
root
通过设置密码、修改配置、重启服务三步可启用腾讯云 Ubuntu 的 root 登录功能。建议仅在必要时开启 root 权限,日常操作优先使用 sudo
命令以提升系统安全性。
本文由阿里云优惠网发布。发布者:编辑员。禁止采集与转载行为,违者必究。出处:https://aliyunyh.com/617382.html
其原创性以及文中表达的观点和判断不代表本网站。如有问题,请联系客服处理。