• Categories
    Category
  • Categories
    Category
  • News
  • Tutorials
  • Forums
  • Tags
  • Users
Tutorial Comments FAQ Related Articles

sudo command in Linux with examples

587

Configuring sudo command

Configuring sudo command and the difference between " su" & " sudo" in Linux distributions is discussed in this article.

The major difference between " su" and " sudo" is, the first compels you to share the root password to other users whereas " sudo" allows you to run commands without root passwords.

Switch to root user, enter the following command in the terminal.

Example

user1@linuxhelp:~$ su
Password:
root@linuxhelp:/home/user1#

To Install " sudo"

By using the following command install " sudo" .

root@linuxhelp:/home/user1# apt-get install sudo

sudo command

Adding username to sudo group

Type the following command, to add username to the group.

root@linuxhelp:/home/user1# adduser user1 sudo
Adding user ' user1'  to group ' sudo' ...
Adding user user1 to group sudo
Done.

Now, add the user name to /etc/sudoers file by using the following command. Hit " Ctrl+x" then press " y" . Finally save the file.

root@linuxhelp:/home/user1# nano /etc/sudoers

add username

To exit out of the Terminal completely, use the following command.

root@linuxhelp:/home/user1# exit
exit
user1@linuxhelp:~$exit

Open a new Terminal and click " Activities" .
activities

Search " Terminal" and press the enter key.
terminal

Type the following command to test.

user1@linuxhelp:~$ sudo ls   

We trust you have received the usual lecture from the local system
Administrator. It ususally boils down to these three things:
#1) Respect the privacy of others.
#2) Think before you type.
#3) With great power comes great responsibility.

[sudo] password for user1:
Desktop Documents Downloads Music Pictures Public Templates Videos

Create a new user, using the adduser command.

user1@linuxhelp:~$ sudo adduser user2

adduser command

To add a new user by using the useradd command

Now to add a new user by using the useradd command

user1@linuxhelp:~$ sudo useradd mark
user1@linuxhelp:~$ sudo passwd mark
Enter new UNIX password:
Retype new UNIX password:
passwd: passwd updated successfully

Delete the created user by running the following command.

user1@linuxhelp:~$ sudo deluser --remove-home mark
Looking for files to backup/remove ...
Removing files ...
Removing user ' mark'  ...
.
.
.
Done.

The --remove-home option will delete the user' s home directory as well.

If you are logged in as root, you do not need to add the sudo before the command.

root@linuxhelp:/home/user1# deluser --remove-home username

To execute ‘ sudo‘ command without entering password

To execute a command without entering password use ‘ NOPASSWD‘ flag.

adam ALL=(ALL) NOPASSWD: PROCS

Here the user " adam" can execute all the commands aliased under “ PROCS” , without entering password.

user1@linuxhelp:~$ sudo nano /etc/sudoers

activities/terminal

To delete the user without entering the sudoers password, run the following command.

user1@linuxhelp:~ sudo deluser --remove-home user2
Looking for files to backup/remove ...
Removing files ...
Removing user ' user2'  ...
Warning: group ' user2'  has no more members.
Done.

To login another user, run the following command

user1@linuxhelp:~$ su - adam
Password:

Enter the following command to test.

adam@linuxhelp:~$ sudo ls
    
We trust you have received the usual lecture from the local system
Administrator. It ususally boils down to these three things:
#1) Respect the privacy of others.
#2) Think before you type.
#3) With great power comes great responsibility.
        
[sudo] password for adam:
adam is not in the sudoers file. This incident will be reported.
adam@linuxhelp:~$ exit
logout

Here, the user is not added in the sudoers file.

Tags:
isaac
Author: 

Comments ( 0 )

No comments available

Add a comment

Frequently asked questions ( 5 )

Q

How to give all privileges to a particular user in sudo functionality?

A

Add the required user to the wheel group.

Q

How to change password in command line for certain users?

A

In order to change the password, use "passwd username"

Q

How to assign 775 permission for the sub-folders in Linux?

A

Use chmod -R 775 followed by the directory path.

Q

What is the major difference between su and sudo?

A

The major difference between " su" and " sudo" is, the first compels you to share the root password with other users whereas " sudo" allows you to run commands without root passwords.

Q

How to add a user to the sudo group?

A

Use command "adduser username sudo" and you can also add the names under "/etc/sudoers" file.

Related Tutorials in sudo command in Linux with examples

Related Tutorials in sudo command in Linux with examples

sudo command in Linux with examples
sudo command in Linux with examples
Jun 18, 2016
How to configure two-factor authentication using sudo in Linux
How to configure two-factor authentication using sudo in Linux
Aug 2, 2016

Related Forums in sudo command in Linux with examples

Related Forums in sudo command in Linux with examples

Dpkg
michael class=
E: dpkg was interrupted, you must manually run 'sudo dpkg --configure -a' to correct the problem
Dec 14, 2018
Linux
nathan class=
How to restrict the user to install packages in linux
Mar 2, 2017
Sudo
lucas class=
How to enable wheel group and add users
Feb 6, 2017
Ubuntu
caden class=
How to set a root password in Ubuntu 18.10
Apr 9, 2019
Sudo
connor class=
how to run root commands without password from sudo user
Feb 22, 2017
CentOS
connor class=
How to add a normal user into the sudoers file On CentOS 7.6
May 31, 2019

Related News in sudo command in Linux with examples

Related News in sudo command in Linux with examples

Patches available for Linux Sudo vulnerability
Patches available for Linux Sudo vulnerability
Jun 1, 2017
UNIX and Linux with Glaring Sudo EnableFlaw Malicious Users to Run Arbitrary Commands
UNIX and Linux with Glaring Sudo EnableFlaw Malicious Users to Run Arbitrary Commands
Oct 19, 2019
Back To Top!
Rank
User
Points

Top Contributers

userNamenaveelansari
135850

Top Contributers

userNameayanbhatti
92510

Top Contributers

userNamehamzaahmed
32150

Top Contributers

1
userNamelinuxhelp
31040

Top Contributers

userNamemuhammadali
24500
Can you help Elijah ?
Remote Desktop Connection Has Stopped Working

When accessing my remote machine server using remote desktop on a windows machine I am getting this error

forum (1)

Networking
  • Routing
  • trunk
  • Netmask
  • Packet Capture
  • domain
  • HTTP Proxy
Server Setup
  • NFS
  • KVM
  • Memory
  • Sendmail
  • WebDAV
  • LXC
Shell Commands
  • Cloud commander
  • Command line archive tools
  • last command
  • Shell
  • terminal
  • Throttle
Desktop Application
  • Linux app
  • Pithos
  • Retrospect
  • Scribe
  • TortoiseHg
  • 4Images
Monitoring Tool
  • Monit
  • Apache Server Monitoring
  • EtherApe 
  • Arpwatch Tool
  • Auditd
  • Barman
Web Application
  • Nutch
  • Amazon VPC
  • FarmWarDeployer
  • Rukovoditel
  • Mirror site
  • Chef
Contact Us | Terms of Use| Privacy Policy| Disclaimer
© 2025 LinuxHelp.com All rights reserved. Linux™ is the registered trademark of Linus Torvalds. This site is not affiliated with linus torvalds in any way.