- How to create a new sudo user on Ubuntu Linux server
- Steps to create a new sudo user on Ubuntu
- More about admin and sudo group on Ubuntu server
- How to add a new user named vivek to sudo using the command line?
- How to add the user named vivek
- How to create a sudo user on Ubuntu for vivek account
- How to print user account info
- How to test sudo access for vivek user account
- How to create a sudo user on Ubuntu and allow SSH login
- Create a sudo user
- 1. Log in to your server as the user with superuser privilege
- 2. Create a new user account
- 3. Add the user to the sudo group
- 4. Test
- Add public key to allow remote SSH login for the new user
- 1. Switch to the new user account
- 2. Create .ssh folder in home directory
- 3. Create authorized_keys file in side the .ssh folder and add the public key
- 4. Verify SSH remote login
- How To Create a New Sudo-enabled User on Ubuntu 18.04 [Quickstart]
- Introduction
- Step 1 — Logging Into Your Server
- Step 2 — Adding a New User to the System
- Step 3 — Adding the User to the sudo Group
- Step 4 — Testing sudo Access
- Conclusion
- How to Create a Sudo User on Ubuntu and Debian
- Adding a sudo user in Ubuntu and Debian
- Step 1: Create a new user [if it doesn’t exist already]
- Step 2: Make it a sudo user
- Step 3: Verify sudo access
- How To Create a Sudo User on Ubuntu [Quickstart]
- Steps to Create a New Sudo User
- Related Tutorials
How to create a new sudo user on Ubuntu Linux server
Steps to create a new sudo user on Ubuntu
- First add the user, run: sudo adduser
- Add the user to sudo group by typing the command in terminal for Ubuntu version 12.04 and above: sudo adduser sudo
- In older version of Ubuntu (version 12.04 and older), run: sudo adduser admin
- Verify it: id
More about admin and sudo group on Ubuntu server
The members of the admin group may gain root privileges. All members of group sudo run any command on Ubuntu server. So just add the user to the sudo group on Ubuntu server. The admin group has been deprecated since Ubuntu version 12.04 and above. Hence, no longer exists or used in Ubuntu 12.04 or above. The reason it works:
# grep -B1 -i ‘^%sudo’ /etc/sudoers
OR
$ sudo grep -B1 -i ‘^%sudo’ /etc/sudoers
Sample outputs:
Let us see some practical examples.
How to add a new user named vivek to sudo using the command line?
Open the terminal or login to your remote server:
$ ssh root@server-name-IP-here
$ ssh root@server1.cyberciti.biz
< root@server:/root>#
How to add the user named vivek
# adduser vivek
OR
$ sudo adduser vivek
Sample outputs:
Fig.01: How to add the new user on Ubuntu
How to create a sudo user on Ubuntu for vivek account
Type the following command:
# adduser vivek sudo
OR use the usermod command to add user to group on Linux:
# usermod -aG sudo vivek
OR
$ sudo usermod -aG sudo vivek
OR
$ sudo adduser vivek sudo
Sample outputs:
Fig.02: Add user vivek to sudo to get administrator privileges
How to print user account info
Verify new user and group membership with the [nicmd name=”id”]:
$ id vivek
Sample outputs:
Fig.03: Show user and group information
- No ads and tracking
- In-depth guides for developers and sysadmins at Opensourceflare✨
- Join my Patreon to support independent content creators and start reading latest guides:
- How to set up Redis sentinel cluster on Ubuntu or Debian Linux
- How To Set Up SSH Keys With YubiKey as two-factor authentication (U2F/FIDO2)
- How to set up Mariadb Galera cluster on Ubuntu or Debian Linux
- A podman tutorial for beginners – part I (run Linux containers without Docker and in daemonless mode)
- How to protect Linux against rogue USB devices using USBGuard
Join Patreon ➔
How to test sudo access for vivek user account
Now user vivek can login using the ssh command command as follows:
$ ssh vivek@server1.cyberciti.biz
Verify that vivek can use sudo command:
$ sudo cat /etc/sudoers
The first time you use sudo command, you will be asked for the password of the vivek account. So type the vivek’s password to gain root access. Any command type with sudo should run with root privileges for vivek account. To gain root shell, enter:
$ sudo -s
Sample outputs:
Fig.03: Testing sudo access for vivek user account
And there you have it. Allowing other users to run sudo on Ubuntu server and granting users administrator privileges.
🐧 Get the latest tutorials on Linux, Open Source & DevOps via
Источник
How to create a sudo user on Ubuntu and allow SSH login
Chi Thuc Nguyen
Aug 7, 2019 · 2 min read
The sudo command is used to allow a permitted user to execute a command as the superuser or another user, as specified by the security policy.
In this guide, I will show you how to create a new user on an Ubuntu server and give it sudo access and allow SSH login to that user.
Create a sudo user
1. Log in to your server as the user with superuser privilege
2. Create a new user account
For this, we use adduser command. Don’t be confused with the useradd command here. useradd is a low level binary command compiled with the system, whereas adduser is a high level Perl script built on top of useradd .
You sho u ld always use adduser to create new user as it provides more user friendly and interactive procedure.
Then follow the instruction to finish the procedure
3. Add the user to the sudo group
On Ubuntu, members of the sudo group have sudo privileges by default.
4. Test
- Switch to the new user account
- Verify the superuser privileges by the sudo command
Add public key to allow remote SSH login for the new user
1. Switch to the new user account
2. Create .ssh folder in home directory
3. Create authorized_keys file in side the .ssh folder and add the public key
Use your favorite text editor for this. I use vim here, for example:
And paste your SSH public key here, save and close file
4. Verify SSH remote login
Open another terminal on your machine and try to remote SSH login using new user.
This should work if you have your SSH private key in
/.ssh/id_rsa file, otherwise you must specify the path to your private key with -i option:
If you can login successfully, congratulations!
Источник
How To Create a New Sudo-enabled User on Ubuntu 18.04 [Quickstart]
Published on March 23, 2020
Not using Ubuntu 18.04?
Choose a different version or distribution.
Introduction
The sudo command provides a mechanism for granting administrator privileges — ordinarily only available to the root user — to normal users. This guide will show you how to create a new user with sudo access on Ubuntu 18.04, without having to modify your server’s /etc/sudoers file. If you want to configure sudo for an existing user, skip to step 3.
Step 1 — Logging Into Your Server
SSH in to your server as the root user:
Step 2 — Adding a New User to the System
Use the adduser command to add a new user to your system:
Be sure to replace sammy with the user name that you want to create. You will be prompted to create and verify a password for the user:
Next you’ll be asked to fill in some information about the new user. It is fine to accept the defaults and leave all of this information blank:
Step 3 — Adding the User to the sudo Group
Use the usermod command to add the user to the sudo group:
Again, be sure to replace sammy with the username you just added. By default, on Ubuntu, all members of the sudo group have full sudo privileges.
Step 4 — Testing sudo Access
To test that the new sudo permissions are working, first use the su command to switch to the new user account:
As the new user, verify that you can use sudo by prepending sudo to the command that you want to run with superuser privileges:
For example, you can list the contents of the /root directory, which is normally only accessible to the root user:
The first time you use sudo in a session, you will be prompted for the password of that users account. Enter the password to proceed:
Note: This is not asking for the root password! Enter the password of the sudo-enabled user, not a root password.
If your user is in the proper group and you entered the password correctly, the command that you issued with sudo will run with root privileges.
Conclusion
In this quickstart tutorial we created a new user account and added it to the sudo group to enable sudo access. For more detailed information on setting up an Ubuntu 18.04 server, please read our Initial Server Setup with Ubuntu 18.04 tutorial.
Источник
How to Create a Sudo User on Ubuntu and Debian
As a sudo user, you can run commands and access files as root user but with your own password. You don’t need to know the root password or switch to root user. You just add sudo before the command to run it with root privilege.
In Ubuntu and Debian-based Linux systems, sudo is practically synonymous with root but in reality, sudo is much more than that.
But I am not going to go into details on sudo here. I’ll just show how you can add a sudo user to Ubuntu or Debian.
That was too short, right? Don’t worry! I explain the steps in detail.
Adding a sudo user in Ubuntu and Debian
I am using Ubuntu in this tutorial, but the steps mentioned here should apply to Debian and many other Linux distributions as well.
The commands used here are standard Linux commands and these should be installed on most Linux distributions by default. However, I am not sure if all Linux distributions have a group named sudo.
Let’s now get started on creating a sudo user or sudoer in Linux command line.
Step 1: Create a new user [if it doesn’t exist already]
Please check the users present on your Linux system. If the user that you want to grant sudo access doesn’t exist, the first step would be to create that user.
Keep in mind that the user will be a regular user when you create it. You add it to the sudoer list in the next step.
Note: Adding a new user will also create a user group named the same as the user in Ubuntu.
To create a user, one must be a sudoer or a root. This is to ensure that only people who are having rights over the system or in charge of protecting the system are creating new users and nobody else.
I am going to use adduser command here.
When you type your password, it will be invisible, but you can also use delete or backspace whenever you like. You may also use Ctrl+U Linux shortcut to delete the entire line and start from the beginning.
Here’s a sample screenshot for the creation of a new user named handbook:
With the adduser command, the home directory for the user is also created.
It also asks for details for name, phone numbers, and others. You may enter the details if you want to, but it is not mandatory. After confirmation, the user will be created successfully.
You may verify the creation of the new user by checking the content of the /home directory or grep on the username in /etc/passwd file.
Step 2: Make it a sudo user
Once the user is created, he/she can be easily converted into sudo user by adding it to the sudo group. Yes, that’s it.
You must use -aG options. The a ensures that you are appending the group.
In the above command:
- usermod changes user’s properties and rights
- –a option tells to append the given group to the user without removing the user from existing groups. If you miss it, the user will be removed from other existing group and that will become a pain for you.
- Option -G lists the groups to which user is to be added. In our case, it is “sudo”. So it is added directly to the command.
Successful addition doesn’t produce any output.
Step 3: Verify sudo access
Now, you should verify if the user has sudo access or not. My favorite way is to use this command:
At the end of this command’s output, you can see if you can run all commands as sudo (ALL : ALL) ALL.
Alternatively, you can change user in command line or simply log out and log in as the new sudo user and then try to run a command as sudo.
From this point, You can write any command that needed sudoer privileges by prepending the command with “sudo”.
That’s it. You successfully created a sudo user.
I hope you liked this quick tip. If you have any questions or suggestions, feel free to leave a comment below.
Источник
How To Create a Sudo User on Ubuntu [Quickstart]
Published on March 28, 2016
Please refer to our Ubuntu 18.04 version of this tutorial instead.
The sudo command provides a mechanism for granting administrator privileges, ordinarily only available to the root user, to normal users. This guide will show you the easiest way to create a new user with sudo access on Ubuntu, without having to modify your server’s sudoers file. If you want to configure sudo for an existing user, simply skip to step 3.
Steps to Create a New Sudo User
Log in to your server as the root user.
Use the adduser command to add a new user to your system.
Be sure to replace username with the user that you want to create.
Set and confirm the new user’s password at the prompt. A strong password is highly recommended!
Follow the prompts to set the new user’s information. It is fine to accept the defaults to leave all of this information blank.
Use the usermod command to add the user to the sudo group.
By default, on Ubuntu, members of the sudo group have sudo privileges.
Test sudo access on new user account
Use the su command to switch to the new user account.
As the new user, verify that you can use sudo by prepending “sudo” to the command that you want to run with superuser privileges.
For example, you can list the contents of the /root directory, which is normally only accessible to the root user.
The first time you use sudo in a session, you will be prompted for the password of the user account. Enter the password to proceed.
If your user is in the proper group and you entered the password correctly, the command that you issued with sudo should run with root privileges.
Related Tutorials
Here is a link to a more detailed user management tutorial:
Источник