{{Header}}
{{Title|
title=Safely Use Root Commands
}}
{{#seo:
|description=Tips on using sudo / root (privileged) commands safely
|image=Root123123.jpg
}}
{{passwords_mininav}}
[[File:Root123123.jpg|250px|thumb]]
{{intro|
This page gives tips on using sudo
/ root (privileged) commands safely. The root account is a special user account in Unix-based operating systems that has complete access to all files and commands on a system. It is typically used only for system administration tasks that require unrestricted access.
}}
= Introduction =
Learn why 'root' is important, what it is used for, and how to use sudo
/ root (privileged) commands safely.
= Rationale for Protecting the Root Account =
{{Anchor|Rationale}}
What is the point on a typical single user Linux desktop computer of separating privileged administrator account (called root
account) and limited user accounts (such as for example user user
)?
It is assumed that most desktop computer users are single user computers. I.e. computers being used by only one person. Rather it is assumed that most users are only using a single login user account which will be referred to as user user
.
Quote [https://xkcd.com/1200/ xkcd authorization]:
If someone steals my laptop while I'm logged in, they can read my email, take my money, and impersonate me to my friends, but at least they can't install drivers without my permission.[https://askubuntu.com/questions/16178/why-is-it-bad-to-log-in-as-root Quote] user discussion:
Most people will consider their home directory as more important than root dirs
Once a malicious program has access to my home folder, I don't care if it also has access to the admin contentThis is true for most users using single user computers, using only one user account and no virtual machines. As a counter measure this is why this documentation [[Special:Search/compartmentalization|recommends compartmentalization]], that is, running different activities in different virtual machines or even on different hardware. The rationale of prevention of root compromise has the following goals: Also see: [[Dev/Strong_Linux_User_Account_Isolation|Permissions]]. * Protect the host operating system: If using {{VM}}: It is much less likely that malware will break out of a virtual machine if it does not have root access within the VM. https://github.com/QubesOS/qubes-issues/issues/2695#issuecomment-301316132 * Protection from rootkits: Root access allow malware to install rootkits, which can be very difficult to detect and remove. * Protect the virtualizer: It is harder to attack the virtualizer without root access. (Applies only when using virtual machines.) * Protect the hardware: A compromised host operating system might result in malware infecting the hardware, i.e. malware could install a persistent hardware backdoor (such as in BIOS or other firmware) surviving even re-installation of the host operating system. In many cases, root access is required before hardware can be attacked. For example flash utilities for Linux require root access. In theory, it's conceivable of software bugs in firmware or hardware resulting in hardware compromise without prior root compromise. No such examples happening in the wild were known to the author at time of writing. * Protect against compromised non-root users: it is harder for potentially compromised non-root users (such as
www-data
) to access user user
or other parts of the system. This is important when considering that even single-user systems have many system-level user accounts.
* Sandboxing: Sandboxing applications can prevent applications getting exploited by attackers
An exploit or payload might require a function which is unavailable inside the sandbox.
or limit the severity of the exploit since if sandboxing is successfully, malware will be trapped inside the sandbox. Sandboxing is a lot harder, less efficient or even impossible when applications are running as root. See also [[AppArmor]], [[apparmor.d|apparmor.d
(Full System AppArmor Profile)]] and [[sandbox-app-launcher]].
{{project_name_short}} implements various security hardening to [[Dev/Strong_Linux_User_Account_Isolation|Enforce Strong Linux User Account Isolation]].
Once proposal [[Dev/user-sysmaint-split|user-sysmaint-split - Multiple Boot Modes for Better Security]] has been implemented there will be a strong guidance for users to better separate their limited (everyday use) account (user
) and administrative account (sysmaint
). This would result in a robust [[root#Prevent Malware from Sniffing the Root Password|Prevention of Malware Sniffing the Root Password]].
= Default Passwords =
The default passwords for {{project_name_short}} are:
{{Default_Passwords}}
The default root account is locked (or should be locked).
In new builds of {{project_name_long}} version 15.0.0.3.6
. Earlier {{project_name_long}} builds did not lock the root account by default and should be locked.
This is a purposeful security feature -- see below for further details.
Users can [[Post_Install_Advice#Change_Passwords|change or set a password]] for security reasons if this is useful in their case based on this [[Default_Passwords#Information|Information]].
= Running with Root Access =
== Run with Administrative Rights ==
To run an application with root rights.
{{IconSet|h2|1}} '''Use a privilege elevation utility to run commands as root.'''
Note: Replace command
with the actual command.
* {{cli}}: {{CodeSelect|inline=true|code=sudo command}}
* {{gui}}: See [[Root#Graphical_Applications_with_Root_Rights|Graphical Applications with Root Rights]].
{{IconSet|h2|2}} '''Password entry.'''
If a password has been configured, the utility will prompt for it.
== User Password versus Root Password ==
Tools such as sudo and lxsudo prompt for the user's password. This is different from the root password.
= Security and Best Practices =
== General Security Advice ==
Commands that require root permissions should be run individually using sudo
. In all cases:
* Do not login as root.
* Do not run sudo su
.
== Inappropriate Use of Root Rights ==
Do not think of root as a shortcut to fix issues.
{{mbox
| image = [[File:Ambox_warning_pn.svg.png|40px]]
| text =
It is very much discouraged to establish the following behavior:application problem
→ "try sudo
/ root".
Only use sudo
/ lxsudo
/ root if there is a strong rationale for doing so. Otherwise...
}}
Inappropriate Use of Root Rights:
* Can cause additional non-security related issues.
* Applications supposed to be run as user but run as root might create root owned files. These file permissions error can lead to additional issues.
* Inter process communications such as with dbus might be broken.
Related is also later chapter [[#Graphical Applications with Root Rights|Graphical Applications with Root Rights]].
* Risks harmful code being run as root.
= Graphical Applications and Root Rights =
{{Anchor|Graphical_Applications_with_Root_Rights}}
{{IconSet|h2|1}} '''Do not run graphical user interface (GUI) with sudo
!'''
It is discouraged to run [https://www.computerhope.com/jargon/g/gui.htm graphical user interface (GUI)] applications with sudo gui-application
.
* Never login as root
as explained above.
* This includes, never use sudo su
and then start GUI applications.
Doing so would be an [[#Inappropriate Use of Root Rights|Inappropriate Use of Root Rights]]. That would fail in many cases and is a limitation inherited from Debian. If this action is attempted, error messages like those below will appear.
* https://help.ubuntu.com/community/RootSudo#Graphical_sudo
* https://www.psychocats.net/ubuntu/graphicalsudo
No protocol specified
cannot connect to X server :0{{IconSet|h2|2}} '''If there is a legitimate reason to start GUI applications with root rights, use
lxsudo
instead.'''
* Reason primarily: not breaking the system, reliability. Non-reason: security.
* https://askubuntu.com/questions/270006/why-should-users-never-use-normal-sudo-to-start-graphical-applications
* In past there was gksudo
, kdesudo
. Nowadays with more and more applications using PolicyKit or polkit, these applications are no longer available as of Debian buster
. lxsudo
is an alternative.
Syntax:
{{CodeSelect|code=
lxsudo application-name
}}
For example to start the partition manager gparted
by default with root rights.
{{CodeSelect|code=
lxsudo gparted
}}
sudo
with -H
/ --set-home
would also be OK. Syntax:
{{CodeSelect|code=
sudo -H application-name
}}
Or.
{{CodeSelect|code=
sudo --set-home application-name
}}
For example to start the partition manager gparted
by default with root rights.
{{CodeSelect|code=
sudo -H gparted
}}
Or.
{{CodeSelect|code=
sudo --set-home gparted
}}
{{IconSet|h2|3}} '''To edit files which can only be edited with root rights. Use the following syntax.'''
Note: Replace /path/to/file/name
with the actual path to the file.
{{Open with root rights|filename=
/path/to/file/name
}}
For example:
{{Open with root rights|filename=
/etc/default/keyboard
}}
== Polkit PolicyKit pkexec for GUI applications ==
{{Anchor|Polkit_PolicyKit_pkexec}}
Use of [https://en.wikipedia.org/wiki/Polkit Polkit] (formerly PolicyKit) (pkexec
) might also be appropriate for running GUI applications with root rights. Usually such applications should have desktop shortcuts or wrappers which make use of pkexec
. There are no (or rare) known cases where users need to run pkexec
on the command line.
== Wayland ==
Running GUI applications as root (lxsudo
, sudo --set-home
, pkexec
will be more difficult once {{project_name_long}} has been ported from X11 to Wayland. This is because Wayland requires applications to access $XDG_RUNTIME_DIR/$WAYLAND_SOCKET
to open GUI windows. https://unix.stackexchange.com/a/423287/535873 You may run into this when using [[Other Desktop Environments]] using Wayland.
The following command should work to run Wayland applications as root in most instances. Replace application-name
as appropriate:
{{CodeSelect|code=
sudo XDG_RUNTIME_DIR=$XDG_RUNTIME_DIR application-name
}}
= Root Account Management =
{{Anchor|Root_Account}}
== Enable Root Account ==
For [[#Rationale|security reasons]] the root account is locked and expired by default in {{project_name_short}} 15.0.0.3.6
and above. For most users there should be no need to use the root account. If it must be enabled for some reason, run the following commands.
([[Qubes|{{q_project_name_long}}]]: {{project_name_gateway_long}} Template)
If you can use sudo
, you can skip the following box.
{{box|text=
If you cannot use sudo
:
* [[{{non_q_project_name_short}}|{{non_q_project_name_short}}]]: Boot into [[Recovery#Recovery_Mode|recovery mode]].
* [[Qubes|{{q_project_name_short}}]]: Open a [[#qubes root console|Qubes Root Console]].
}}
{{IconSet|h2|1}} Unexpire the root account.
{{CodeSelect|code=
sudo chage --expiredate -1 root
}}
{{IconSet|h2|2}} Set a root password.
According to the [[Post_Install_Advice#Change_Password|Change Password]] instructions. Note: These instructions are for the user user
account. Replace user user
with root
.
== Disable Root Account ==
[[Old Stable and Earlier Releases|Earlier versions]] of {{project_name_short}} (version numbers lower than 15.0.0.3.6
) come with the root account enabled by default. Most users should disable it by running the following commands.
([[Qubes|{{q_project_name_short}}]]: {{project_name_gateway_short}} Template).
Lock the account.
{{CodeSelect|code=
sudo passwd --lock root
}}
No longer expiring the root account since this broke adduser, see: https://forums.whonix.org/t/restrict-root-access/7658/59
(To prevent SSH login, see: [https://www.cyberciti.biz/faq/linux-locking-an-account/ Linux Locking An Account]. This might prevent other login methods but this requires further investigation.)
{{CodeSelect|code=
sudo chage --expiredate 0 root
}}
In the future, [[#General Security Advice|use sudo
instead]] when it is necessary.
{{Anchor|unlock}}
== Avoid Root Login ==
Should the user login as root
? No. See footnote for rationale.
Why not login as root? This is for reasons of history, legacy.
Even during the times of X11, root
login was frowned upon.
Therefore for strong user isolation, logging in as root
user is to be avoided.
In an ideal world, the extra sysmaint
user would be unnecessary and people could simply use the root
user. Or even better, all references to root
would be removed and replaced with sysmaint
. However, this kind of education and convincing among many upstream projects for the purpose of [[Dev/Strong Linux User Account Isolation]] is totally unrealistic for organisational reasons, which are elaborated on the [[Linux User Experience versus Commercial Operating Systems]] page.
{{sdebian
|link=https://www.debian.org/doc/manuals/securing-debian-manual/ch04s11.en.html#idm1382
|text=Using su
}}
= Troubleshooting =
== Permissions Fix ==
After [[#Inappropriate Use of Root Rights|inappropriate use of root rights]], attempt to fix:
{{Open a product ws terminal}}
Run the following command to reset permissions of user user
's home folder /home/user
back to owner user
and group user
.
{{CodeSelect|code=
sudo chown --recursive user:user /home/user
}}
== Reset User Account Password ==
The following steps can be used in case the password has been forgotten and needs to be reset.
{{Box|text=
{{IconSet|h2|1}} '''Launch a root terminal.'''
* [[{{non_q_project_name_short}}|{{non_q_project_name_short}}]]: Boot into [[Recovery#Recovery_Mode|recovery mode]].
* [[Qubes|{{q_project_name_short}}]]: Open a [[#qubes root console|Qubes Root Console]].
{{IconSet|h2|2}} '''Notes'''.
* This process will be similar to the [[Post_Install_Advice#Change_Password|change password]] wiki chapter which is recommended to read as it contains instructions / links on how to change and test the keyboard layout.
* This is [[unspecific|unspecific to {{project_name_short}}]]. It should be a very similar process on Debian or most other Linux distributions. It can also be resolved as per [[Self Support First Policy]].
{{IconSet|h2|3}} '''Set a new password.'''
Run the following command.
{{CodeSelect|code=
sudo passwd user
}}
{{IconSet|h2|4}} '''Reboot.'''
{{CodeSelect|code=
sudo reboot
}}
{{IconSet|h2|5}} '''Done.'''
The process of password reset has been completed.
}}
== Unlock User Account: Excessive Wrong Password Entry Attempts ==
The following steps can be used in case the user entered the wrong password too many times, which resulted in the user account being automatically locked. (This is related to security feature [[Dev/Strong_Linux_User_Account_Isolation#Bruteforcing_Linux_User_Account_Passwords_Protection|Bruteforcing Linux User Account Passwords Protection]].)
{{Box|text=
{{IconSet|h2|1}} '''Launch a terminal that can run commands as root.'''
If you cannot login anymore, see the bullet points below:
* [[{{non_q_project_name_short}}|{{non_q_project_name_short}}]]: Boot into [[Recovery#Recovery_Mode|recovery mode]].
* [[{{q_project_name_short}}|{{q_project_name_short}}]]: Open a [[#qubes root console|Qubes Root Console]].
{{IconSet|h2|2}} '''Run the following command.'''
Note: Replace user
with the actual name of the user that you wish to unlock.
{{CodeSelect|code=
sudo faillock --user user --reset
}}
{{IconSet|h2|3}} '''Done.'''
Unlocking of user account has been completed.
}}
{{Anchor|console}}
== Console Unlock ==
{{Box|text=
{{IconSet|h2|1}} '''Launch a root terminal.'''
* [[{{non_q_project_name_short}}|{{non_q_project_name_short}}]]: Boot into [[Recovery#Recovery_Mode|recovery mode]].
* [[Qubes|{{q_project_name_short}}]]: Open a [[#qubes root console|Qubes Root Console]].
{{IconSet|h2|2}} '''Run the following command.'''
Note: Replace user
with the Linux user account name which should be allowed to login on the [[login]] console.
{{CodeSelect|code=
sudo adduser user console
}}
}}
= Advanced Users =
== Prevent Malware from Sniffing the Root Password ==
== Rationale for Separate sysmaint Account ==
{{anchor|Rationale for Separate admin Account}}
If Linux user account user
is compromised, malware can easily steal the administrative ("sudo
") password.
Any graphical application can see what is typed in another graphical application, for any user.
[https://blog.invisiblethings.org/2011/04/23/linux-security-circus-on-gui-isolation.html Quote] Joanna Rutkowska, security researcher, founder and advisor (formerly architecture, security, and development) of Qubes OS:
One application can sniff or inject keystrokes to another one, can take snapshots of the screen occupied by windows belonging to another one, etc.If an application is compromised with an exploit due to a security vulnerability, it can be used as malware by the attacker. Once/if the application is not effectively confined by a mandatory access control (MAC) framework like AppArmor or firejail, it can compromise the user account where it is running and then proceed from there. See also [[Dev/Strong_Linux_User_Account_Isolation#sudo_password_sniffing|sudo password sniffing]] for technical details. Therefore it is more secure ([[#Rationale|rationale)]] to perform administrative actions such as running
sudo
from a separate sysmaint
account that is less likely to get compromised, since this reduces the chances of malware sniffing the password to escalate to administrative ("root") access.
The basic concept is a separation of the following users:
* '''user user
:''' Perform everyday actions such as running web browsers.
* '''user sysmaint
:''' Perform system maintenance administrative actions such as installing additional packages.
Questions and answers:
* Is running applications such as browser under user sysmaint
less secure? Yes, that defeats this concept.
* Is running applications such as browser under user user
more secure? Yes, because it becomes harder for malware to perform privilege escalation attacks to gain to administrative ("root") access.
* What is so bad about malware escalating to administrative? See [[#Rationale|rationale]].
* Why use user sysmaint
and not simply the root
user? See [[Root#Avoid_Root_Login|Avoid Root Login]].
This process is currently for advanced users only since it is quite cumbersome, i.e. has bad usability. The usability of this will be improved once proposal [[Dev/user-sysmaint-split|user-sysmaint-split - Multiple Boot Modes for Better Security]] has been implemented.
=== Overview of Steps ===
To more securely perform administrative tasks that require root access, see the following overview steps below. Detailed technical steps are available further below.
# Prerequisite knowledge: [[Desktop#Virtual_Consoles|how to switch to a different virtual console]], [[SysRq|usage of the SysRq key]] and [[Login spoofing|login spoofing]].
# These instructions are ideally applied after installing the host / VM when it is still considered free of [[Malware and Firmware Trojans|malware]].
# Create a new user account sysmaint
.
# Add it to the group sudo
.
# Login as user sysmaint
.
# Remove user user
from group sudo
.
# Only then perform administrative tasks according to the instructions below.
=== Detailed Steps ===
This setup only needs to be completed once.
{{IconSet|h2|1}} '''Platform specific notice:'''
* {{non_q_project_name_short}}: No special notice.
* ([[Qubes|{{q_project_name_short}}]]: {{project_name_workstation_long}} Template)
{{IconSet|h2|2}} '''Create a new user account sysmaint
.'''
{{CodeSelect|code=
sudo adduser sysmaint
}}
{{IconSet|h2|3}} '''Add user sysmaint
to group sudo
and console
.'''
{{CodeSelect|code=
sudo adduser sysmaint sudo
}}
Allow login into [[login]] console.
{{CodeSelect|code=
sudo adduser sysmaint console
}}
{{IconSet|h2|4}} '''Perform the following steps securely using sudo
. Use one of the methods below.'''
{{Tab
|type=controller
|content=
{{Tab
|title= ===Non-GUI Environment Method===
|type=section
|content=
* Advantage: can keep current user session(s) and/or graphical session (X Window System) running.
* Disadvantages: cannot use graphical session during administrative tasks
Unless perhaps advanced users manage to run a different X server on a different virtual console. This might not be possible, secure. Depends on if the exclusive lock of X can be suspended while using an X server in a different virtual console. This has not been researched.
and requires SysRq, which is [[SysRq#Kicksecure_Default_SysRq_Configuration|disabled by default in Kicksecure for security reasons]].
{{IconSet|h3|1}} [[SysRq#Enable_SysRq|Enable SysRq]].
{{IconSet|h3|2}} Make sure keyboard gets disconnected from X Window System to [[Login spoofing|defeat login spoofing]]. (unraw
)
This step might be unnecessary. Not researched yet.
[[SysRq]] + w
(Press Alt + SysRq + w
)
{{IconSet|h3|3}} Switch to another [[Desktop#Virtual_Consoles|virtual console]].
(Press Alt + Crtl + F2
)
Pressing Alt + Crtl + F7
results in tty2
.
This is to make these instructions compatible with most Linux distributions as well as Qubes.
* Most Linux distributions login CLI virtual consoles on tty1
(Alt + Crtl + F1
) by default and X Window System on tty7
(Alt + Crtl + F7
).
* Qubes X Window System by default runs on tty1
. (Alt + Crtl + F1
)
tty2
(Alt + Crtl + F2
) will be for most users an unused virtual console which can be used for the purpose of this chapter.
{{IconSet|h3|4}} Press Secure Access Key also to [[Login spoofing|defeat login spoofing]].
[[SysRq]] + k
(Press Alt + SysRq + k
)
{{IconSet|h3|5}} Login as user sysmaint
from that non-graphical environment ([[Desktop#Virtual_Consoles|virtual console]]).
An X Window System non-root user cannot sniff keystrokes of different (non-)root users utilizing a different virtual console (tty
).
{{IconSet|h3|6}} Perform any necessary administrative tasks.
{{IconSet|h3|7}} Remove user user
from group sudo
.
Note: This only needs to be performed once.
{{CodeSelect|code=
sudo delgroup user sudo
}}
{{IconSet|h3|8}} Logout user sysmaint
.
{{CodeSelect|code=
logout
}}
{{IconSet|h3|9}} Switch back to previous virtual console.
X Window System runs in:
* most Linux distributions: virtual console 7
(Press Alt + Crtl + F7
)
* Qubes: virtual console 1
(Press Alt + Crtl + F1
)
{{IconSet|h3|10}} Re-login if needed and continue usual work as user user
.
}}
{{Tab
|title= ===Logout Method===
|type=section
|content=
* Advantage: can use graphical session (X Window System) during administrative tasks using privileged user sysmaint
.
* Disadvantage: cannot keep graphical session of unprivileged user user
running. In other words, simplified, all applications run under user user
will be terminated
Non-simplified: applications run by user user
in a different virtual console or run through systemd (user) services can be left running.
and requires SysRq, which is [[SysRq#Kicksecure_Default_SysRq_Configuration|disabled by default in Kicksecure for security reasons]].
{{IconSet|h3|1}} Terminate all running applications in current graphical (X) session.
{{IconSet|h3|2}} Log out.
start menu -> log out
{{IconSet|h3|3}} Make sure keyboard gets disconnected from X Window System to [[Login spoofing|defeat login spoofing]]. (unraw
)
[[SysRq]] + w
(Press Alt + SysRq + w
)
{{IconSet|h3|4}} Press Secure Access Key also to [[Login spoofing|defeat login spoofing]].
[[SysRq]] + k
(Press Alt + SysRq + k
)
{{IconSet|h3|5}} Login as user sysmaint
.
{{IconSet|h3|6}} Perform any necessary administrative tasks.
{{IconSet|h3|7}} Remove user user
from group sudo
.
Note: This step only needs to be performed once.
{{CodeSelect|code=
sudo delgroup user sudo
}}
{{IconSet|h3|8}} Logout user sysmaint
.
{{IconSet|h3|9}} Re-login as user user
.
{{IconSet|h3|10}} Continue usual work as user user
.
}}
{{Tab
|title= ===Power-off and Power-on Cycle Method===
|type=section
|content=
* Advantages: Use graphical session during administrative tasks. No need for complicated user of SysRq.
* Disadvantages: Cannot keep graphical session of unprivileged user user
running. In other words, simplified, all applications run under user user
will be terminated.
{{IconSet|h3|1}} Power off.
Shutdown the system. Really power off. Not shutdown. Why? To defeat [[login spoofing]].
{{IconSet|h3|2}} Power on.
{{IconSet|h3|3}} Do not login as user user
.
{{IconSet|h3|4}} Login as user sysmaint
.
{{IconSet|h3|5}} Perform any necessary administrative tasks.
{{IconSet|h3|6}} Remove user user
from group sudo
.
Note: This step only needs to be performed once.
{{IconSet|h3|7}} Power off.
{{IconSet|h3|8}} Continue usual work as user user
.
}}
}}
== Substitute User (su) Command ==
The majority of users do not need to utilize the su
command.
su
is sometimes incorrectly referred to as the ''superuser'' command. [http://www.linfo.org/su.html It allows]:
... a change to a login session's owner (i.e., the user who originally created that session by logging on to the system) without the owner having to first log out of that session. Although su can be used to change the ownership of a session to any user, it is most commonly employed to change the ownership from an ordinary user to the root (i.e., administrative) user, thereby providing access to all parts of and all commands on the computer or system.By comparison,
sudo
makes it possible to execute system commands without the root password.
.
In {{project_name_short}}, by default:
* [https://github.com/{{project_name_short}}/security-misc/blob/master/usr/share/pam-configs/wheel-security-misc group sudo
membership is required to use su
].
Implemented in package [https://github.com/{{project_name_short}}/security-misc security-misc].
* User user
is a member of group sudo
. ([[Dev/user-sysmaint-split|This might change in a later release.]])
{{Box|text=
To permit the su
command from user user
, complete the following steps.
([[Qubes|{{q_project_name_short}}]]: perform these steps in {{project_name_gateway_short}} Template.)
{{IconSet|h2|1}} '''[[#Enable Root Account|Enable the root account]].'''
{{IconSet|h2|2}} '''Add user user
to group root
.'''
{{CodeSelect|code=
sudo adduser user root
}}
{{IconSet|h2|3}} '''[[SUID_Disabler_and_Permission_Hardener#Re-enable_Specific_SUID_Binaries|Re-enable SUID]].'''
Set suid. Note: It is okay if the second command fails.
{{CodeSelect|code=
sudo permission-hardener disable /bin/su
sudo permission-hardener disable /usr/bin/su
}}
{{CodeSelect|code=
sudo chmod 4755 /bin/su
sudo chmod 4755 /usr/bin/su
}}
{{IconSet|h2|4}} '''[[SUID_Disabler_and_Permission_Hardener#Whitelist_Specific_SUID_Binaries|Add SUID whitelisting]].'''
{{CodeSelect|code=
sudo mkdir -p /etc/permission-hardener.d
}}
{{Open with root rights|filename=
/etc/permission-hardener.d/20_user.conf
}}
Add.
{{CodeSelect|code=
/bin/su exactwhitelist
/usr/bin/su exactwhitelist
}}
{{IconSet|h2|5}} '''Save.'''
{{IconSet|h2|6}} '''Done.'''
Steps to permit su
command from user user
are complete.
}}
{{Anchor|login}}
== Root Login ==
Root login within a [[Desktop#Virtual_Consoles|virtual console]] will be disabled by default after upgrades. security-misc [https://github.com/{{project_name_short}}/security-misc/blob/master/etc/securetty.security-misc /etc/securetty]
is empty by default. When trying to login as root in a [[Desktop#Virtual_Consoles|virtual console]] it will reply: Login incorrect.Without previously asking for a password. This is not the worst case for usability and is better than asking for password and then failing. To enable login from a [[Desktop#Virtual Console|virtual console]], first apply the [[#Enable Root Account|Enable Root Account]] instructions further above, then complete the steps below. {{Box|text= {{IconSet|h2|1}} '''To allow root login,
/etc/securetty
must be configured. '''
sudoedit
will not follow symlinks, therefore realpath
is used.
{{Open with root rights|filename=
$(realpath /etc/securetty)
}}
{{IconSet|h2|2}} '''Add the following content.'''
Note: Add one or more tty depending on your circumstances; see file /etc/securetty.security-misc-orig
.
* [[{{non_q_project_name_short}}|{{non_q_project_name_short}}]]:
{{CodeSelect|code=
tty1
tty2
tty3
tty4
tty5
tty6
tty7
tty8
tty9
tty10
}}
* [[Qubes|{{q_project_name_short}}]]:
{{CodeSelect|code=
hvc0
}}
{{IconSet|h2|3}} '''Save the file.'''
}}
== Recovery Mode ==
Root login is possible using [[Recovery#Recovery_Mode|recovery mode]].
https://forums.whonix.org/t/restrict-root-access/7658/46
When the root account is disabled, passwordless root login using recovery mode is possible; see below for the security impact.
== Passwordless Recovery Mode Security Discussion ==
This is only relevant on the host and not inside virtual machines.
Passwordless recovery mode is allowed because a locked root password would break the rescue and emergency shell. Therefore the [https://github.com/{{project_name_short}}/security-misc security-misc] package enables a passwordless rescue and emergency shell. This is the same solution that Debian will likely adapt for Debian installer.
* https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=802211
* /etc/systemd/system/emergency.service.d/override.conf
* /etc/systemd/system/rescue.service.d/override.conf
With passwordless root login, using recovery mode is allowed (through use of the security-misc package) on the host. To prevent adverse security effects posed by lesser adversaries with physical access to the machine, set up BIOS password protection, bootloader grub password protection and/or [[Full_Disk_Encryption|full disk encryption]].
{{anchor|qubes root console}}
== Qubes Root Console ==
The following will open a root console inside a Qubes VM.
{{Box|text=
{{IconSet|h2|1}} '''Open a dom0 terminal.'''
Qubes App Launcher (blue/grey "Q")
→ System Tools
→ Xfce Terminal
{{IconSet|h2|2}} '''Run the following command.'''
Replace vm-name
with the name of the actual VM where you want to open a root console.
{{CodeSelect|code=
qvm-run -u root vm-name xfce4-terminal
}}
{{IconSet|h2|3}} '''Done.'''
A Qubes root console will now be available.
}}
== Qubes Passwordless Root Access Setup ==
The following can be used to set up passwordless root access for specific Qubes VMs.
{{Box|text=
{{IconSet|h2|1}} '''Open a [[#Qubes Root Console|Qubes Root Console]].'''
{{IconSet|h2|2}} '''Temporary passwordless root access until reboot.'''
Run the following command.
{{CodeSelect|code=
echo "user ALL=(ALL:ALL) NOPASSWD:ALL" {{!}} EDITOR=tee visudo -f /etc/sudoers.d/nopassword >/dev/null
}}
{{IconSet|h2|3}} '''Permanent passwordless root access after reboot.'''
Run the following command.
{{CodeSelect|code=
echo 'echo "user ALL=(ALL:ALL) NOPASSWD:ALL" {{!}} EDITOR=tee visudo -f /etc/sudoers.d/nopassword >/dev/null' {{!}} tee -a /rw/config/rc.local >/dev/null
}}
{{IconSet|h2|4}} '''Make Qubes VM specific startup script /rw/config/rc.local
executable.'''
{{CodeSelect|code=
chmod +x /rw/config/rc.local
}}
{{IconSet|h2|5}} '''Done.'''
}}
NOTE: In 17.2.3.8 and above this can be simplified to 1 command.
{{CodeSelect|code=
passwordless-root
}}
{{Anchor|dsudo}}
== dsudo - default password sudo ==
dsudo
is a {{project_name_short}} specific feature.
https://forums.whonix.org/t/dsudo-default-password-sudo/8766
As long as still using the [[#Default Password|default password]] (not having [[Post_Install_Advice#Change_Passwords|changed sudo password]]), commands can be run as root without entering a password. This is useful for users having issues with [[Keyboard Layout|changing the keyboard layout]] and for testing VMs.
Instead of using
{{CodeSelect|code=
sudo
}}
use
{{CodeSelect|code=
dsudo
}}
== passwordless-root ==
TODO: document
After [[Dev/user-sysmaint-split|Role-Based Boot Modes (user versus sysmaint)]] has been implemented, some users may want to get back to traditional way of allowing user user
to use sudo
.
Next version of {{project_name_long}} will come with [https://github.com/Kicksecure/usability-misc/blob/master/usr/bin/passwordless-root /usr/bin/passwordless-root
]. A tool to easily set up passwordless sudo
for user user
.
Platform specific:
* Non-Qubes: The computer user must boot into sysmaint
mode first.
* Qubes: The computer user needs to open a [[Root#Qubes_Root_Console|Qubes Root Console]]. passwordless-root
can simplify [[Root#Qubes_Passwordless_Root_Access_Setup|Qubes Passwordless Root Access Setup]]
Execution of passwordless-root
requires root.
{{CodeSelect|code=
passwordless-root
}}
= Definitions =
== Rooted ==
{{anchor|Definition of Rooted}}
What does it mean to be "rooted"? The word "rooted" in the context of computer security, smartphones, and root isolation is used in different ways.
A device can get "rooted" by at least two different entities:
* A) '''user''': Intentional rooting by the user grants them full administrative rights and is typically carried out to overcome restrictions imposed by the manufacturer or operating system (e.g., to uninstall bloatware or customize the OS).
* B) '''malware''': Malware-induced rooting occurs when malicious software exploits vulnerabilities to gain privileged access without user consent, often for nefarious purposes such as installing malicious programs, gaining deeper access to sensitive data, malware persistence.
Linux desktop operating system (Debian, Fedora, Kicksecure, Whonix, and most others) specific example:
* '''Definition:''' If sudo
is configured to allow user user
to run commands without a password, the machine can be considered rooted by the user.
* '''In technical terms:''' File /etc/sudoers.d/user-passwordless
contains content user ALL=(ALL:ALL) NOPASSWD:ALL
.
* '''Implications:''' This means the user will be able to run sudo some-command
to execute a command with administrative ("root") rights without a password. The user could even run sudo su
to switch to user root
.
Qubes specific example: If package qubes-core-agent-passwordless-root
gets installed, then the VM has been rooted by the user. The implications are the same as above. On the other hand, if the user opens a [[Root#Qubes_Root_Console|Qubes Root Console]], the VM should not be considered rooted.
Malware specific example: If a web server (such as nginx
running under a limited Linux account user nginx
) gets compromised, the malware could attempt to root the device (synonym of saying "root the operating system"). This is also often called local privilege escalation (LPE), which refers to exploiting vulnerabilities, misconfigurations, or using other techniques to escalate permissions from a regular user to a higher privilege level, typically the "root" user.
Android specific example: If the user manages to get an Android Root Management Tool such as SuperSU, Magisk, or Superuser by ChainsDD to be functional, then the device is typically considered "rooted by the user". On the other hand, if a compromised or malicious app accomplishes LPE, then the device can be considered "rooted by malware".
Unclear definitions: What if on a Linux desktop distribution, user user
can gain root rights after using sudo
and entering a password? Typically, for Linux desktop distributions this is not considered "rooted". The word "rooted" is mostly used on mobile operating systems Android and iOS.
Difference in Terminology:
* '''Desktop Linux''': The concept of "rooting" is not usually applied to traditional Linux desktops. Instead, users elevate privileges with sudo
, which is considered a normal administrative function. The term "rooted" implies a fundamental change in the system's security model that is not present when using standard privilege escalation like sudo
.
* '''Mobile OS (Android/iOS)''': "Rooting" or "jailbreaking" signifies that the device’s default restrictions are bypassed, giving the user continuous and unrestricted access to system files and functions.
Malicious Root Management Tools: Are an Android / iOS specific issue. Some websites say, that for example KingRoot for Android is malware.
https://ivonblog.com/en-us/posts/kingroot-is-a-malware/
This issue does not exist for Linux desktop distributions. Tools such as su
, sudo
, doas
are Open Source, Freedom Software and generally not considered malware. The existence of malicious root management tools and other issues (documented on [[Mobile_Phone_Security#Administrative_Rights|Mobile Devices Privacy and Security, Administrative Rights]]) are among reasons why rooting is often discouraged for mobile devices. However, a blanket recommendation to avoid rooting in all cases for all use cases cannot be deduced from that.
Related:
* [[Miscellaneous_Threats_to_User_Freedom#Administrative_Rights|General Threats to User Freedom, Administrative Rights Refusal]]
* [[Verified Boot]]
== sudoless ==
Different people have used the term "sudoless" for very different meanings.
* 2015: [https://gist.github.com/ivandokov/9328c98202b45104fa3e ivandokov/sudoless]: means passwordless sudo
. The ability of a specific Linux user account name such as "user
" to run sudo
without a password.
* 2021: [https://andyyang.co.uk/synology-nas-how-to-run-docker-commands-without-sudo/ How to run Docker commands without sudo on a Synology NAS: A quick guide to enable sudoless docker commands.]
* 2022: [https://forums.kicksecure.com/t/sudoless-kicksecure/139 a Kicksecure user forum post]: used "sudoless" as a synonym for "passwordless".
* 2023: [https://www.techrepublic.com/article/enable-podman-sudoless-container-management/ TechRebuplic: How to enable Podman sudo-less container management]
* 2024: [https://github.com/secureblue/secureblue/releases/tag/v4.2.0 secureblue]: used "sudoless" in context of removal of sudo
, su
and pkexec
. (Related: [[Dev/secureblue|Comparison of secureblue with Kicksecure and Development Notes]], chapter [[Dev/secureblue#sudoless|sudoless]].)
The term "sudoless" can therefore be confusing, should either be avoided or clarified when used.
= See Also =
* [[SysRq|System Recovery using SysRq Key]]
* [[Login spoofing]]
* [[Dev/Strong_Linux_User_Account_Isolation|Strong Linux User Account Isolation]]
= Development =
* {{project_name_short}} code: [https://github.com/{{project_name_short}}/security-misc/pull/22 Restrict access to the root account].
* https://forums.whonix.org/t/sysrq-magic-sysrq-key/8079/68
* https://forums.whonix.org/t/should-lesser-adversaries-with-physical-access-be-part-of-the-threat-model-of-whonix-whonix-host-kicksecure/7997
= Attribution =
{{sdebian
|link=https://www.debian.org/doc/manuals/securing-debian-manual/ch04s11.en.html#idm1391
|text=Using sudo
}}
= Footnotes =
{{reflist|close=1}}
[[Category:Documentation]]
{{Footer}}