Linux user with root privileges

add new user with root access in Linux

I want to add new user and have/grant that new user to have all the root access, how can I do that ? I did sudo adduser —system testuser but this is not working as I expected. Thanks for help.

8 Answers 8

There are actually three ways you can do this: the right way, the wrong way, and the ugly way.

First, create a normal user account.

Then select one of the following:

The Right Way

Create a sudo entry for the wheel group in /etc/sudoers like this:

## Allows people in group wheel to run all commands %wheel ALL=(ALL) ALL 
## Allows people in group sudoers to run all commands %sudoers ALL=(ALL) ALL 

Then add the user to the wheel group. Adding and removing users with administrative priviledges now becomes a function of remembering to add them to wheel, instead of creating an entry in sudo. The great thing about using wheel is that you can extend this mechanism into other authentication schemes that support groups, i.e. winbind/Active Directory, and reap the benefits in the process. You would accomplish this by mapping wheel to a group in your authentication schema that has admin privileges.

Note that some distributions use different administrative accounts. Wheel is a «traditional» approach to this, but you may encounter admin , adm , and other group accounts that serve the same purpose.

I have to give a point to Bart Silverstrim for pointing out that Ubuntu uses admin as the group for this purpose. He got to this first, although I didn’t notice an Ubuntu tag at the time. Again, it all depends on what distribution your are using.

The Ugly Way

Create a sudo entry for the user account in question and give then complete access. Again, you create the entry in /etc/sudoers like this:

## Allows just user "username" to run all commands as root username ALL=(ALL) ALL 

ADDED: ## For Ubuntu version: username ALL=(ALL:ALL)

This is great if you only have one (or two) normal accounts. It is ugly when you have a hundred accounts over multiple (geophysical) sites and have to constantly maintain the sudo file.

The Wrong Way

You can edit the /etc/passwd file and change the user account ID from whatever number it is, to 0 . That’s right, zero.

username:x:0:502::/home/username:/bin/bash 

See that third entry as zero? When you log into that account, you are, for all effective purposes, root . I do not recommend this. If you do not remember «who» you are, you can create all kinds of havoc as you start creating and touching files as root . You could also add your username to the root group. This has the same effect for file access but it creates other issues; programs will notice you are not user root and refuse to run, but you will gain access to files that belong to group root .

Читайте также:  Networking command line linux

If you did this, you did use vipw instead of just editing with vi , right? (or whatever your favorite text editor is) After all, a single typo in this file can lock you out of your system — and that means a physical visit to the computer in question with a repair disc.

Источник

How To Create a New Sudo-enabled User on Ubuntu 20.04 [Quickstart]

How To Create a New Sudo-enabled User on Ubuntu 20.04 [Quickstart]

When managing a server, you’ll sometimes want to allow users to execute commands as “root,” the administrator-level user. The sudo command provides system administrators with a way to grant administrator privileges — ordinarily only available to the root user — to normal users.

In this tutorial, you’ll learn how to create a new user with sudo access on Ubuntu 20.04 without having to modify your server’s /etc/sudoers file.

Note: 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 username that you want to create. You will be prompted to create and verify a password for the user:

Output
Enter new UNIX password: Retype new UNIX password: passwd: password updated successfully

Next, you’ll be asked to fill in some information about the new user. It is fine to accept the defaults and leave this information blank:

Output
Changing the user information for sammy Enter the new value, or press ENTER for the default Full Name []: Room Number []: Work Phone []: Home Phone []: Other []: Is the information correct? [Y/n]

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 user’s account. Enter the password to proceed:

Output:
[sudo] password for sammy:

Note: This is not asking for the root password! Enter the password of the sudo-enabled user you just created.

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.

Читайте также:  How to delete deleted files in linux

Conclusion

In this quickstart tutorial, we created a new user account and added it to the sudo group to enable sudo access.

For your new user to be granted external access, please follow our section on Enabling External Access for Your Regular User.

If you need more detailed information on setting up an Ubuntu 20.04 server, please read our Initial Server Setup with Ubuntu 20.04 tutorial.

Get Ubuntu on a hosted virtual machine in seconds with DigitalOcean Droplets! Simple enough for any user, powerful enough for fast-growing applications or businesses.

Источник

How to Give Root Privileges to a User in Linux

The “root” super user is the king of users in Linux/Unix. Having root access grants full and unlimited access to the Linux box.

The root or super user has full permission to read(r), write (w) and execute(x) any file. By default root user id is ‘0’.

In this tutorial, I will show you how to allow root access to a user in a Linux system. Typically, root level access is used in system administration. So it is always a pain to give root access to other users. You need to be careful and should withdraw the access once the need to do so is over.

Remember: It’s safer to perform superuser tasks using sudo command than log in as a root account.

I am going to create two users namely user1 and user2. Then I will show you how to give root access to ‘user1’.

Method 1: Adding to Root Group using usermod

Let’s see how we can grant normal user root access by adding to root group.

adduser user1 adduser user2 groupadd test

These are the groups I have in my Linux box.

groups root bin daemon sys adm disk wheel

I am going to add user1 to root group as follows:

The following usermod command given below provides the existing user with the root privilege

Method 2: Adding to Root Group using Useradd Command

I have added a new user, ‘user3’ to the root group using one single command:

useradd -m -G root user3 groups user3 user3 : user3 root

Another option using useradd command

useradd -c “Imitation Root” -d /home/root_user -m -k /etc/skel -s /bin/bash -u 0 -o -g root root_user

Method 3: Editing /etc/passwd file

Edit /etc/passwd for the particular user. Change the user’s UID and GID to ‘0’. This will give root permissions to user.

root:x:0:0:root:/root:/bin/bash temproot:x:128:128:temproot

Now, temproot user should have root privilege:

root:x:0:0:root:/root:/bin/bash temproot:x:0:0:temproot

Note: This is not the recommended method for granting root access

Method 4: Setting as Sudo User

The sudo configuration file is /etc/sudoers and you can edit this file using visudo command: # visudo.

Using visudo protects from conflicts and guarantees that the right syntax is used.

To give full access (grant root privileges) to specific users

Add the entry given below in the file:

Following this method is not a good idea because this allows both bob and tom to use the su command to grant themselves permanent root privileges. Thereby skipping the command logging features of sudo.

Granting access to specific files to one particular user

This entry allows bob and all the other members of the group operator to gain access to all the program files in the /sbin and /usr/sbin directories, as well as the privilege of running the command /usr/oracle/backup.pl.

bob, %operator ALL= /sbin/, /usr/sbin, /usr/oracle/backup.pl

Conclusion

In this tutorial, we learned how to allow root access to a user in a Linux system.

Читайте также:  Linux tun or tap

Login in as root and running commands is dangerous because all commands are with the highest privileges. Accident mistakes can even delete root directories and unsafe to run programs with a root shell.

If this resource helped you, let us know your care by a Thanks Tweet. Tweet a thanks

Источник

How To Create a New Sudo-enabled User on Ubuntu 18.04 [Quickstart]

How To Create a New Sudo-enabled User on Ubuntu 18.04 [Quickstart]

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:

Output
Enter new UNIX password: Retype new UNIX password: passwd: password updated successfully

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:

Output
Changing the user information for sammy Enter the new value, or press ENTER for the default Full Name []: Room Number []: Work Phone []: Home Phone []: Other []: Is the information correct? [Y/n]

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:

Output:
[sudo] password for sammy:

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.

Thanks for learning with the DigitalOcean Community. Check out our offerings for compute, storage, networking, and managed databases.

Источник

Оцените статью
Adblock
detector