• Categories
    Category
    {{ postCtrl.tags }}
    • {{ category.tag_type }}

      • {{tag.tag_name}}
      • View more
  • Categories
    Category
    {{ postCtrl.tags }}
    • {{ category.tag_type }}

      • {{tag.tag_name}}
      • View more
  • News
  • Tutorials
  • Forums
  • Tags
  • Users
Tutorial News Comments FAQ Related Articles

sudo command in Linux with examples

{{postValue.id}}

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
{{postCtrl.cmtErrMsg}}

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.

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 Luke ?
workbench for debian

I am using workbench in CentOS whereas now I need to use Debian Operating system so could you please help to install and use in Debian?

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.