Using the sudo Command
If a user has been granted sudo
access then that user can run administrative
commands with elevated privileges:
sudo command
Depending on the sudoer
configuration, the user might also be prompted for a
password.
Preserving environment variables
In some situations, a user might have set environment variables that they want to reuse or
preserve while running elevated commands. They can do this by using the -E
option.
Example 6-1 Accessing user proxy settings within a sudo session
For example, if the Oracle Linux system is connected to an enterprise intranet or virtual private network (VPN), proxy settings might be required to obtain outbound Internet access.
Terminal commands rely on the http_proxy
, https_proxy
and
no_proxy
environment variables. You can set them in the
$HOME/.bashrc
configuration file:
export http_proxy=http://proxy.example.com:8080
export https_proxy=https://proxy.example.com:8080
export no_proxy=localhost,127.0.0.1
Run the source
command to refresh the session environment variables without
signing out:
source $HOME/.bashrc
The sudo
command can use the proxy settings that you have configured as
environment variables within the user's session. For example, to run the curl
command with administrative privileges:
sudo -E curl https://www.example.com
Note:
An administrator can optionally set system-wide proxy environment variables by configuring
them in a shell script and then saving that file in the /etc/profile.d/
directory.
For more information about configuring network settings, see Oracle Linux 10: Setting Up Networking With NetworkManager.
Elevating to a root shell
You can also use sudo
access to start an elevated root
shell. The -s
option elevates the user to a root
shell as
the root
user. The -i
option elevates the user to a
root
shell while preserving both the user profile and shell
configuration:
sudo -i
Exiting sudo
When you have finished running administrative commands, exit the root
shell
and return to the standard user privilege level by using the exit
command.