Linux добавить пользователя правами root

HowTo: Grant Root Access to User – Root Privileges – Linux

From this article you’ll learn how to create a user in Linux and grant root access to him or how to grant root privileges to already existent user.

This can be easily done by changing UID (user id) and GID (group id) in /etc/passwd file.

Also you will learn how to just add user to root group and i will explain how to delete user with root privileges.

Actually it is not a good idea to give all the privileges of root to a non-root user and outside the test environment i would not recommend to have multiply superusers.

Warning: Giving a non-root user all the permissions of root is very dangerous, because the non-root user will be able to do literally anything that could cause a big trouble if account is hijacked.

Check SSH Server Settings: If you have disabled root access in SSH server settings, by setting PermitRootLogin no in /etc/ssh/sshd_config – you won’t be able to login if your user has UID 0 .

Warning: Before moving forward, read the comments below and DON’T FOLLOW THE STEPS FROM THIS ARTICLE if you don’t understand of what you are doing and what impact this may have!

Grant Root Privileges To New User

To create a user with exactly the same privileges as root user, we have to assign him the same user ID as the root user has ( UID 0 ) and the same group ID ( GID 0 ).

Use the following commands to create a user john , grand him the same privileges as root and set him a password:

$ sudo useradd -ou 0 -g 0 john $ sudo passwd john

Grant Root Privileges To Existent User

Cool Tip: Dot the i’s and cross the t’s on file and folder permissions in Linux! Make it more clear! Read more →

Perhaps you already have a user john and you want to grant him root privileges (make him a second root user):

$ grep john /etc/passwd john:x:1001:1001::/home/alice:/bin/sh

For this, it is required to edit the file /etc/passwd and just change UID and GID to 0 :

$ grep john /etc/passwd john:x:0:0::/home/john:/bin/sh

Add User To Root Group

If you just want to add john to root group, without granting him all root privileges, run the following command:

$ sudo usermod -a -G root john

Delete User With Root Privileges

Cool Tip: Log in to a remote Linux server without entering password! Set up password-less SSH login! Read more →

Читайте также:  Linux перезапустить wifi адаптер

You won’t be able to delete a user with UID 0 using userdel command:

$ sudo userdel john userdel: user john is currently used by process 1

To delete him, firstly open the /etc/passwd file and change his UID .

For example, change the line:

After this, you’ll be able to delete user john with userdel command:

46 Replies to “HowTo: Grant Root Access to User – Root Privileges – Linux”

“For this, it is required to edit the file /etc/passwd and just change UID and GID to 0”
WRONG.
Baaaad idea. Much regret. Undo, undo.

ntfs@brix:~$ ssh 192.168.88.16 -l pi
pi@192.168.88.16‘s password:
Permission denied, please try again.
pi@192.168.88.16‘s password:
Permission denied, please try again.
– – –
Nice explanation?)

Since noone elaborate how to undo this broken way of adding users, I will. The only way is to successful login to the linux machine, if you login via ssh or tty.
If you add a user with uid 0 to group uid 0, and you set in sshd_config AllowRootLogin NO, you`re access will be denied. So you will have to login to the linux machine via tty (this is the only way if you don`t have a correctly added backup user on the linux machine). Via tty you can login with any of the users, even root.
The correct way to add a user with root privileges is adding the user the normal way, useradd -m user, and then add privileges with visudo to the user.
So if you have a backup user that haves root privileges in visudo. you will be able to login to the linux machine via ssh, and you will be able to change the uid and group to the “broken” user.
I think this article explains more likely how to add a user with root privileges “the hacker way (which is a broken way)”, and repair the broken way after.
Also if you don`t have access to a tty console, and you want to test the commands of this article and be sure you did not broke something, STAY LOGGED in current session and open another one and test if all things are OK. If you can`t login in the new session, you still have opened the previous session and you can repair what have you broken.
Hope it helps to repair further mistakes.

Читайте также:  Сменить графическую оболочку linux mint

Источник

Linux добавить пользователя правами root

В Ubuntu-системе, да и в принципе, в любой другой Linux-системе, обязательно есть один привилегированный пользователь — root.

sudo — утилита, которая дает привилегии root для выполнения административных операций.

Простым языком команда sudo позволяет пользователям Ubuntu выполнять команды от имени суперпользователя root, либо других пользователей.

Создание пользователя с привилегиями Sudo

Сперва, при помощи команды «adduser» создаем нового пользователя.

sudo adduser *имя_пользователя*

При создании пользователя будет предложено ввести пароль и другие необязательные данные (Имя, Номер комнаты, Телефон и тд), указываем их по своему желанию.

Обращаем внимание, что только суперпользователь с правами root имеет право добавлять новых пользователей в Ubuntu. Следовательно, запускаем команду adduser с sudo.

Добавляем пользователя в группу Sudo

Следующим шагом является добавление созданного пользователя в группу sudo, которая выдаст пользователю все привилегии sudo:

sudo adduser *имя_пользователя* sudo

При успешном добавлении в группу Sudo получим уведомление в терминале Ubuntu: «Добавление пользователя *имя* в группу sudo. Готово.».

Отлично! Пользователь добавлен в группу sudo, теперь проверим, есть ли у него привилегии sudo.

Тестирование пользователя Sudo

Переключаемся на вновь созданного пользователя (пользователь с именем admin в нашем случае) при помощи команды «su»:

После того, как мы войдем в систему под новым пользователем, мы получим сообщение, как правильно использовать команду «sudo» — «To run a command as administrator (user *root*), use *sudo command*».

Данное уведомление в терминале будет означает, что пользователь находится в группе sudo.

Теперь можно запустить команду с sudo для нового пользователя и проверить, сработает ли она. Давайте создадим каталог «papka» внутри папки «/etc» (только root-пользователь имеет право вносить изменения в данной папке, поэтому потребуется sudo доступ). Итак, вводим команду на создание нового каталога:

При запросе пароля, вводим его. Проверяем созданную папку командой «ls».

Либо переходим в «etc» через проводник Ubuntu.

Отлично! Как мы видим через «ls» или проводник, каталог «papka» успешно создан в «etc».

Источник

How To Create A New Sudo Enabled User on Ubuntu 22.04 [Quickstart]

How To Create A New Sudo Enabled User on Ubuntu 22.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 22.04 without having to modify your server’s /etc/sudoers file.

Читайте также:  Manjaro linux update command

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.

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 22.04 server, please read our Initial Server Setup with Ubuntu 22.04 tutorial.

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

Источник

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