Linux creating admin user

How can I create an administrator user from the command line?

@JizoSaves Generally speaking, it depends. adduser is more interactive, and useradd is designed for scripts.

4 Answers 4

Add the user to the sudo group with:

(If you’re running Ubuntu 11.10 or earlier, use the admin group.)

Default values are stored in /etc/adduser.conf , you can check them with

To create a user and add it directly to the sudo group use

(Again, use admin in place of sudo for 11.10 and earlier.)

Have a look at all the options you have with adduser here.

This is the first line of using -D : Option d is ambiguous (debug, disabled-login, disabled-password) . adduser interprets it as a mistake and tells you all the flags and options you can use . Definitely got nothing to do with defaults.

To create a new user with admin privileges in Ubuntu 12.04 and later:

In Ubuntu 11.10 and earlier, use this instead:

To modify a existing user (12.04 and later):

(Or for 11.10 and earlier: sudo usermod -aG admin )

-a stands for append whereas -G stands for groups. With the -a and -G flags as shown above, the sudo (or admin ) group will be added to the list of groups of which the user is a member.

When I do adduser foobar sudo before creating the user, in Xenial it says «adduser: the username `foobar’ does not exist», and it’s not shown in /etc/passwd , so I believe the user is not created.

On Trusty I get this: «` $ sudo adduser neue —group sudo adduser: Please specify a single name in this mode. $ sudo adduser neue sudo adduser: The user ‘neue’ does not exist. «`

The other answers are correct but you also asked about the home directory. You will also need a password for the new user.

sudo useradd *new-admin-username* -s /bin/bash -g sudo -m 
  • -s sets the user’s login shell
  • -m makes the user’s home directory if it doesn’t exist: /home/*new-admin-username*
  • -g adds the user to the sudo group so they will have admin privileges (>11.10)

Once created, add a password for the user:

sudo passwd *new-admin-username* 

Login to the user to see if everything worked:

su *new-admin-username* cd ~/ pwd 

Источник

How to create a new user with admin privileges on Linux

Adding a user with admin privileges on Linux is easier than you think. Jack Wallen shows you how.

We may be compensated by vendors who appear on this page through methods such as affiliate links or sponsored partnerships. This may influence how and where their products appear on our site, but vendors cannot pay to influence the content of our reviews. For more info, visit our Terms of Use page.

Читайте также:  Linux run command as system user

Must-read security coverage

  • Google offers certificate in cybersecurity, no dorm room required
  • The top 6 enterprise VPN solutions to use in 2023
  • EY survey: Tech leaders to invest in AI, 5G, cybersecurity, big data, metaverse
  • Electronic data retention policy (TechRepublic Premium)

If you’re a Linux system admin, you probably find yourself scrambling to keep everything in check every day. There’s a lot to be done and doing this with a nod to security makes the task even more challenging. That’s why you dole out tasks to those admins under you. After all, if you attempt to do everything yourself, eventually you’re going to make a mistake, and mistakes can be disastrous in today’s light speed world of business. You create new users on your Linux servers and let those admins do their thing.

Problem is, when you create a new user, that user doesn’t have admin privileges. What do you do? Let me show you. In fact, I’m going to walk you through the process of creating an admin-ready user on Linux with just a few quick commands. I’ll demonstrate this on both Ubuntu Server 20.04 and CentOS 8, so you should be able to handle the task no matter what distribution you’re on.

SEE: Linux service control commands (TechRepublic Premium)

What you’ll need

How to create a sudo-able user on Ubuntu Server

First, we’ll demonstrate how this is done on Ubuntu Server. Here, you can take care of creating the user with only two commands. The first command will create the new user:

Where USERNAME is the name of the user you want to add.

The adduser command will not only have you create a password for the user, but also have you enter the following (optional) details:

The adduser command will also automatically create the new user’s home directory, so you don’t have to worry about that.

With the new user created, it’s time to give them sudo rights. For this we’ll use the usermod command like so:

sudo usermod -aG sudo USER

Where USER is the new username.

You’ve just created a new user and given them sudo privileges on Ubuntu Server.

How to create a sudo-able user on CentOS

Here we have to take an extra step. First we create the user with command:

Where USER is the username to be added. We include the -m option to ensure the home directory is created along with the user.

Next, we need to set the password for the user. However, we’re going to set the password such that the user will have to change their password upon first login. To do that we first must set an initial password with the command:

Where USER is the new username we created.

This will prompt you to type and verify a new password. Once you’ve set that, you can then expire the password with the command:

Where USER is the new username we created.

Finally, we give the user admin privileges with the command:

sudo usermod -aG wheel USER

Where USER is the new username we created.

There you have it–you’ve created a new user and given them sudo privileges on both Ubuntu and CentOS. Now you only have to hope those users will employ sudo with caution.

Читайте также:  Программирование с файлами linux

How to remove sudo rights

If you find one of your admins not using sudo with respect to your policies, you might have to remove their rights. To do that, you’ll edit the /etc/group file and remove their name from either the sudo or the wheel entry. To do that, issue the command:

Scan through that file for either the sudo (Ubuntu) or wheel (CentOS) entry (Figure A). When you find it, you should see the new user listed. Remove them from that line, save and close the file, and that user will no longer have sudo privileges.

And that’s all there is to creating new users with admin privileges on Linux.

Subscribe to the Cybersecurity Insider Newsletter

Strengthen your organization’s IT security defenses by keeping abreast of the latest cybersecurity news, solutions, and best practices.

Delivered Tuesdays and Thursdays

  • Cybersecurity and cyberwar: More must-read coverage (TechRepublic on Flipboard)

Also See

Источник

Создание нового пользователя с привилегиями sudo в Ubuntu 18.04 [Краткое руководство]

Создание нового пользователя с привилегиями sudo в Ubuntu 18.04 [Краткое руководство]

Команда sudo служит механизмом для предоставления прав администратора, которые обычно доступны только пользователю root user, для обычных пользователей. Из этого руководства вы узнаете, как создать нового пользователя с привилегиями sudo в Ubuntu 18.04 без изменения файла /etc/sudoers ​​​ на вашем сервере. Если вы хотите настроить sudo для существующего пользователя, перейдите к шагу 3.

Шаг 1 — Выполнение входа на ваш сервер

Выполните вход через подключение SSH на ваш сервер как root user:

Шаг 2 — Добавление нового пользователя в систему

Используйте команду adduser для добавления нового пользователя в вашей системе:

Обязательно замените sammy на имя пользователя, которое вы хотите использовать. Вам будет предложено создать и проверить пароль пользователя:

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

Далее вам будет предложено ввести определенную информацию о вашем новом пользователе. Вы можете принимать значения по умолчанию или оставить их пустыми:

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]

Шаг 3 — Добавление пользователя в группу sudo

Воспользуйтесь командой usermod для добавления пользователя в группу sudo:

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

Шаг 4 — Тестирование доступа к sudo

Чтобы проверить, что новые разрешения sudo доступны, сначала нужно воспользоваться командой su для переключения на новую учетную запись пользователя:

Используя нового пользователя, убедитесь, что вы можете использовать sudo , добавив sudo перед командой, которую вы хотите запустить с привилегиями суперпользователя:

Например, вы можете вывести список содержимого директории /root , которое обычно доступно только для пользователя root user:

При первом использовании sudo в сеансе вам будет предложено ввести пароль учетной записи данного пользователя. Введите пароль, чтобы продолжить:

Output:
[sudo] password for sammy:

Примечание: это не запрос пароля root! Введите пароль пользователя с привилегиями sudo, а не пароль root.

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

Заключение

В этом кратком руководстве мы создали новую учетную запись пользователя, добавили ее в группу sudo и предоставили доступ к sudo . Более подробную информацию по настройке сервера Ubuntu 18.04 см. в нашем руководстве по первоначальной настройке сервера Ubuntu 18.04.

Читайте также:  Linux mount status 32

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

Источник

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.

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.

Источник

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