Atlantic.Net Blog

How to Setup Passwordless Sudo for a Specific User

Hitesh Jethva
by Atlantic.Net (85posts) under VPS Hosting
0 Comments

In a Linux system, the root user is a superuser that has permission to access everything on the server. A standard user account only has limited privileges and can run only specific commands on the system.

The sudo command elevates a standard user account, granting root access to the system. Every time you sudo a sudo command you will be prompted for the sudoer password, which can become repetitive. However, there is a great way to securely configure a passwordless sudo account

In this tutorial, we will show you how to set up Passwordless Sudo in Linux.

Prerequisites

  • A fresh Ubuntu 18.04 VPS on the Atlantic.Net Cloud Platform.
  • A root password configured on your server.

Step 1 – Create Atlantic.Net Cloud Server

First, log in to your Atlantic.Net Cloud Server.  Create a new server, choosing Ubuntu 18.04 as the operating system with at least 1GB RAM. Connect to your Cloud Server via SSH and log in using the credentials highlighted at the top of the page.

Once you are logged into your Ubuntu 18.04 server, run the following command to update your base system with the latest available packages.

apt-get update -y

Step 2 – Configure Passwordless Sudo For a Specific User

If you want to allow a user named vyom to execute sudo without a password, edit the /etc/sudoers file:

nano /etc/sudoers

Add the following line at the end of the file:

your_username ALL=(ALL:ALL) NOPASSWD:ALL

For example:

Atlantic-Admin ALL=(ALL:ALL) NOPASSWD:ALL

Save and close the file.

Then, run any superuser command with sudo:

sudo fdisk -l

You don’t need to provide any password after running the above command.

Step 3 – Configure Passwordless Sudo For a Specific Group

If you want to allow a member of a specific group named www-data to execute sudo without a password, edit the /etc/sudoers file:

nano /etc/sudoers

Add the following line at the end of the file:

%www-data  ALL=(ALL:ALL) NOPASSWD:ALL

Save and close the file when you are finished.

Step 4 – Configure Passwordless Sudo For All Users

If you want to allow all users to execute sudo without a password (note: this is only advisable in test systems and should never be used on production workloads), edit the /etc/sudoers file:

nano /etc/sudoers

Find the following line:

%sudo   ALL=(ALL:ALL) ALL

Replace it with the following line:

%sudo   ALL=(ALL:ALL) NOPASSWD:ALL

Step 5 – Configure Passwordless Sudo For Specific User to Execute Only Specific Command

If you want to allow a specific user named vyom to execute only “fdisk -l” command  without password, edit the /etc/sudoers file:

nano /etc/sudoers

Add the following line at the end of the file:

your_username  ALL=(ALL:ALL) NOPASSWD: /sbin/fdisk -l

Save and close the file when you are finished.

Now, only the user can only run the “fdisk -l” command without a password.

Conclusion

In the above guide, you have learned how to configure passwordless sudo for a specific group, specific user and all users. Ready to get started with Passwordless Sudo in Linux? Get VPS Hosting from Atlantic.Net today!

Get A Free To Use Cloud VPS

Free Tier Includes:
G2.1GB Cloud VPS Free to Use for One Year
50 GB of Block Storage Free to Use for One Year
50 GB of Snapshots Free to Use for One Year


Looking for a Hosting Solution?

We Provide Cloud, Dedicated, & Colocation.

  • Seven Global Data Center Locations.
  • Flexible Private, Public, & Hybrid Hosting.
  • 24x7x365 Security, Support, & Monitoring.
Contact Us Now! Med Tech Award FTC
SOC Audit HIPAA Audit HITECH Audit

Recent Posts

Get started with 12 months of free cloud VPS hosting

Free Tier includes:
G2.1GB Cloud VPS Server Free to Use for One Year
50 GB of Block Storage Free to Use for One Year
50 GB of Snapshots Free to Use for One Year


New York, NY

100 Delawanna Ave, Suite 1

Clifton, NJ 07014

United States

San Francisco, CA

2820 Northwestern Pkwy,

Santa Clara, CA 95051

United States

Dallas, TX

2323 Bryan Street,

Dallas, Texas 75201

United States

Ashburn, VA

1807 Michael Faraday Ct,

Reston, VA 20190

United States

Orlando, FL

440 W Kennedy Blvd, Suite 3

Orlando, FL 32810

United States

Toronto, Canada

20 Pullman Ct, Scarborough,

Ontario M1X 1E4

Canada

London, UK

14 Liverpool Road, Slough,

Berkshire SL1 4QZ

United Kingdom

Resources