永久使用与临时使用
在某些情况下,您可能需要长时间使用超级用户 root。在这些情况下,我们可以通过简单的操作sudo su
(将要求当前用户的密码)轻松访问 root 帐户,选择 Kali 菜单中的 root 终端图标,或者使用su -
(将要求 root 用户的密码)(如果您有)为您知道的 root 帐户设置密码。完成后,exit
或 CTRL+D 将使我们退出这个提升的 shell。
但是,有时您可能希望在多个会话中使用 root 权限,而不必担心提升权限的麻烦。在这些情况下,由于默认情况下禁用 root 帐户的安全原因,我们需要安装一个软件包并进行一些修改以完全启用 root 帐户的使用。
启用Root帐户
首先要做的是设置 root 密码,该密码应该与当前用户的密码不同(在本例中kali
)。我们可以通过执行以下操作来做到这一点:
kali@kali:~$ sudo passwd
[sudo] password for kali:
New password:
Retype new password:
passwd: password updated successfully
kali@kali:~$
- 请注意,当您输入密码时,密码提示不会显示输出,但它仍会记录击键。
为 SSH 启用 root
kali@kali:~$ grep PermitRootLogin /etc/ssh/sshd_config
#PermitRootLogin prohibit-password
# the setting of "PermitRootLogin without-password".
kali@kali:~$
kali@kali:~$ man sshd_config | grep -C 1 prohibit-password
PermitRootLogin
Specifies whether root can log in using ssh(1). The argument must be yes, prohibit-password, forced-commands-only, or no. The default
is prohibit-password.
If this option is set to prohibit-password (or its deprecated alias, without-password), password and keyboard-interactive authentication
are disabled for root.
kali@kali:~$
kali@kali:~$ sudo systemctl restart ssh
kali@kali:~$
如果我们已经为 root 帐户设置了基于 SSH 密钥的登录,那么我们可以简单地取消注释相应的行并继续。否则,我们应该将PermitRootLogin更改为yes,这将允许我们输入密码。
启用 GNOME 和 KDE 登录 root
我们将首先安装kali-root-login
并更改多个配置文件,这些文件将允许我们通过 GNOME GDM3 和 KDE 登录提示登录 root 帐户。使用其他桌面环境时不需要此步骤:
kali@kali:~$ sudo apt -y install kali-root-login
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following NEW packages will be installed:
kali-root-login
0 upgraded, 1 newly installed, 0 to remove and 1516 not upgraded.
Need to get 6,776 B of archives.
After this operation, 33.8 kB of additional disk space will be used.
Get:1 http://kali.download/kali kali-rolling/main amd64 kali-root-login all 2019.4.0 [6,776 B]
Fetched 6,776 B in 1s (10.9 kB/s)
Selecting previously unselected package kali-root-login.
(Reading database ... 333464 files and directories currently installed.)
Preparing to unpack .../kali-root-login_2019.4.0_all.deb ...
Adding 'diversion of /etc/gdm3/daemon.conf to /etc/gdm3/daemon.conf.original by kali-root-login'
Adding 'diversion of /etc/pam.d/gdm-password to /etc/pam.d/gdm-password.original by kali-root-login'
Adding 'diversion of /etc/pam.d/gdm-autologin to /etc/pam.d/gdm-autologin.original by kali-root-login'
Adding 'diversion of /etc/pam.d/lightdm-autologin to /etc/pam.d/lightdm-autologin.original by kali-root-login'
Adding 'diversion of /etc/pam.d/sddm to /etc/pam.d/sddm.original by kali-root-login'
Adding 'diversion of /etc/sddm.conf to /etc/sddm.conf.original by kali-root-login'
Unpacking kali-root-login (2019.4.0) ...
Setting up kali-root-login (2019.4.0) ...
Installing /usr/share/kali-root-login/daemon.conf as /etc/gdm3/daemon.conf
Installing /usr/share/kali-root-login/gdm-password as /etc/pam.d/gdm-password
Installing /usr/share/kali-root-login/gdm-autologin as /etc/pam.d/gdm-autologin
Installing /usr/share/kali-root-login/lightdm-autologin as /etc/pam.d/lightdm-autologin
Installing /usr/share/kali-root-login/sddm as /etc/pam.d/sddm
Installing /usr/share/kali-root-login/sddm.conf as /etc/sddm.conf
kali@kali:~$
- 现在,我们可以注销非 root 用户帐户并使用我们之前设置的密码登录到 root。
请登录后查看回复内容