ubuntu linux root password

本文介绍了Ubuntu Linux中默认锁定的root账号的使用方法。包括如何通过sudo命令执行管理员任务,避免直接登录root账号带来的风险。

Ubuntu Linux root Password (Default Password)

Ihave just installed Ubuntu Linux. But, what is the default root password? I can only login as a normal user. How do I login as root user?

This is the mystery for most users – you didn’t set a root password, so what is it? The root user (also known as superuser), is a user on Ubuntu Linux and Unix-like systems with full administrative privileges (full access). So using root account for daily work can be very dangerous and you may damage your working system.

Ubuntu and root account

By default root account is locked under Ubuntu Linux. Therefore, you cannot login as root or use ‘su -‘ command to become a superuser. To run all administrative command use sudo command. sudo allows a permitted user to execute a command as the superuser or another user. Ubuntu setup your default account (the one created during installation) to run all administrative commands.

For example create a new user called bar, you need to type sudo command as follows:
$ sudo adduser bar
Password:

When sudo asks for a password, you need to supply YOUR OWN password. In other words a root password is not needed. Here are few more examples.

Task: Start / stop / restart services stored in /etc/init.d/ directory

$ sudo /etc/init.d/ssh stop
$ sudo /etc/init.d/networking restart

Task: Avoid typing sudo each and every time

Note that this is not recommended until and unless you are an expert and aware of what you are typing:
$ sudo -i

Above command will start /bin/bash as a root shell so that you can enter a root user command without using sudo command.

How do I login as root user?

Open terminal and simply type the following command:
$ sudo bash
OR
$ sudo -s
Supply your password and you will become a root user.

### 重置 Ubuntu 系统 Root 密码的方法 如果忘记了 Ubuntu 系统的 root 密码,可以通过以下方法重新设置密码: #### 方法一:通过 GRUB 编辑模式重置密码 1. **进入 GRUB 菜单** 开机或重启系统时,按下 `Shift` 键调出 GRUB 启动菜单。对于虚拟机环境(如 VirtualBox),可能需要多次按压 `Shift` 键才能显示 GRUB 菜单。 2. **编辑启动参数** 使用方向键选择默认的 Ubuntu 启动项,然后按下 `e` 键进入编辑模式。此时可以看到启动参数配置界面[^2]。 3. **修改启动参数** 找到以 `linux /boot/vmlinuz...` 开头的一行,在该行中找到类似于 `ro quiet splash $vt_handoff` 的部分,将其替换为 `rw init=/bin/bash`。此更改允许系统以可读写模式启动,并直接进入根 shell[^2]。 4. **重启并验证权限** 按下 `Ctrl + X` 或 `F10` 继续启动系统。系统将跳过正常初始化流程,直接进入带有完全访问权限的 root shell 环境。在此环境中运行以下命令以确认文件系统具有读写权限: ```bash mount | grep 'on / ' ``` 如果输出结果显示 `/` 是只读挂载,则需手动重新挂载为可写状态: ```bash mount -o remount,rw / ``` 5. **重置 root 密码** 运行以下命令来更新 root 用户的密码: ```bash passwd root ``` 输入新密码并再次确认。完成后会出现提示信息 `password updated successfully` 表明操作成功[^1]。 6. **退出并重启系统** 完成密码更改后,执行以下命令使系统恢复正常启动: ```bash exec /sbin/init ``` --- #### 方法二:通过恢复模式重置密码 1. **进入 GRUB 菜单** 类似于方法一,开机时按住 `Shift` 键进入 GRUB 菜单。 2. **选择高级选项** 使用方向键导航至 `Advanced options for Ubuntu` 并回车。 3. **启用恢复模式** 在高级选项列表中选择带 `(recovery mode)` 字样的条目,随后按 Enter 键继续。 4. **打开根 Shell 提示符** 在恢复菜单中选择 `Drop to root shell prompt` 选项,这将提供一个具备超级用户权限的终端窗口[^3]。 5. **解锁文件系统** 默认情况下,恢复模式下的文件系统是以只读方式挂载的。因此需要先解除锁定以便能够修改数据: ```bash mount -o remount,rw / ``` 6. **重设 root 密码** 和方法一同样地使用 `passwd root` 命令完成密码设定工作。 7. **重启设备** 修改完毕之后,输入以下指令让计算机重新引导回到常规桌面环境: ```bash reboot ``` --- ### 注意事项 - 更改后的 root 密码务必妥善保管,建议记录在一个安全的地方以防遗忘。 - 若希望禁用登录时对 root 账户的要求或者进一步加强安全性,请考虑调整 SSH 配置或其他相关服务设置。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值