(Using Sudo)

sudo (Super User DO) command in Linux is generally used as a prefix of some command that only superuser are allowed to run. If you prefix "sudo" with any command, it volition run that command with elevated privileges or in other words permit a user with proper permissions to execute a command as another user, such as the superuser. This is the equivalent of "run as administrator" pick in Windows. The option of sudo lets u.s. have multiple administrators.
These users who can use the sudo control demand to take an entry in the sudoers file located at "/etc/sudoers". Call back that to edit or view the sudoers file you have to use sudo command. To edit the sudoers file information technology is recommended to use "visudo" command.
Past default, sudo requires that users cosign themselves with a password which is the user's password, not the root password itself.

sudoers file:

Syntax:

sudo -V | -h | -l | -v | -m | -Yard | -s | [ -H ] [-P ] [-S ] [ -b ] |
[ -p prompt ] [ -c class|- ] [ -a auth_type ] [-r role ] [-t type ]
[ -u username|#uid ] commandsudo -5 | -h | -l | -L | -v | -one thousand | -K | -s | [ -H ] [-P ] [-S ] [ -b ] |
[ -p prompt ] [ -c class|- ] [ -a auth_type ] [-r part ] [-t type ]
[ -u username|#uid ] command

Options

ane. -V: The -V (version) pick causes sudo to print the version number and exit. If the invoking user is already root, the -V selection will print out a list of the defaults sudo was compiled with.

2. -l: The -50 (list) option will print out the commands immune (and forbidden) the user on the current host.

This shows the current user can utilise all commands as sudo.

3. -h or –help: The -h (aid) option causes sudo to print a usage message and exit.

4. -v: If, given the -v (validate) option, sudo will update the user's timestamp, prompting for the user'due south password if necessary. This extends the sudo timeout for another 5 minutes (or every bit given in sudoers) but does not run a command. This does not give whatsoever output.

5. -k: The -k (kill) selection to sudo invalidates the user'due south timestamp.So, the next time sudo is run a password will be required. This option does non require a password and was added to allow a user to revoke sudo permissions from a .logout file.

half dozen. -K: Similar to the -k option, the -Thousand (sure kill) option is used to remove the user's timestamp entirely. As well, this pick does not require a password.

7. -b: The -b (background) option tells sudo to run the given control in the groundwork. Annotation that if you use the -b option y'all cannot apply shell job control to manipulate the process.

8. -p:The -p (prompt) selection allows you to override the default countersign prompt and use a custom ane. The post-obit percentage ('%') escapes are supported:

%u is expanded to the invoking user'south login name;

%U is expanded to the login name of the user the command will be run as (which defaults to root);

%h is expanded to the local hostname without the domain name;

%H is expanded to the local hostname including the domain name (only if the machine's hostname is fully qualified or the "fqdn" sudoers pick is fix);

%% (2 consecutive % characters) are collapsed into a unmarried % character.

Normally we get this for a sudo control:

Using sudo -p nosotros get,

9. -northward: Use -north option as shown below, which will execute the command without prompting for the password. This is very helpful when nosotros want to run some of the sudo commands as background jobs (or in a beat script), where we don't want sudo to enquire for the password. -n pick stands for non-interactive.

10. -u: The -u (user) option causes sudo to run the specified control as a user other than root. To specify a uid instead of a username, use #uid.

11. -south: The -s (shell) option runs the shell specified by the SHELL environment variable if it is fix or the shell as specified in the file passwd.

12. -H: The -H (Domicile) option sets the Abode environment variable to the home directory of the target user (root past default) equally specified in passwd. By default, sudo does not modify HOME.

thirteen. -Southward: The -Southward (stdin) pick causes sudo to read the countersign from standard input instead of the concluding device.

14. -a: The -a (hallmark blazon) option causes sudo to utilize the specified authentication type when validating the user, every bit immune past /etc/login.conf. The system administrator may specify a list of sudo-specific authentication methods by calculation an "auth-sudo" entry in /etc/login.conf.

15. –: The — flag indicates that sudo should stop processing command line arguments. It is well-nigh useful in conjunction with the -south flag.

Environment Variables

These environment variables are used by sudo

Tag Description
EDITOR
Default editor to use in -eastward (sudoedit) style if VISUAL is not set
Habitation
In -s or -H mode (or if sudo was configured with the
–enable-shell-sets-domicile option), set to homedir of the target user
PATH
Set to a sane value if the secure_path sudoers choice is gear up.
Trounce
Used to determine shell to run with -s pick
SUDO_PROMPT
Used equally the default password prompt
SUDO_COMMAND
Set to the command run past sudo
SUDO_USER
Gear up to the login of the user who invoked sudo
SUDO_UID
Set to the uid of the user who invoked sudo
SUDO_GID
Set up to the gid of the user who invoked sudo
SUDO_PS1
If set up, PS1 will exist set to its value
USER
Fix to the target user (root unless the -u option is specified)
VISUAL
Default editor to use in -e (sudoedit) mode

lunahaventruckew.blogspot.com

Source: https://www.geeksforgeeks.org/sudo-command-in-linux-with-examples/

0 Response to "(Using Sudo)"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel