Linux how to create root user

How can I create a root user from the start of installing Ubuntu?

How can I create a root user from the start of Ubuntu installation? When I tried it, it showed that this user name has already been reserved.

If you want a root user by default use another OS than Ubuntu that uses the root model. CentOS, SUSE.

You don’t need to create a root user; it is created automatically, which is why you can’t create one since it already exists. But that’s probably not your real question.

the best way is, after creating the normal account, log in to the root account and completely remove the normal account, and also what like normal account related files it creates. but how to? I want others for help!

3 Answers 3

The user root already exists by default when a Linux system is created, or at least, a user must exist with UID 0 who has all permissions and owns most of the system files. Traditionally this user is called root. You do not need to create that user.

When you install Ubuntu, you are prompted to create a user for yourself. This is because it is inadvisable to run the system as root, because root always has all permissions and programs run as root may do whatever they want, which is a security risk. Running commands and other programs as an unprivileged user wherever possible is safer. But, the user you create at installation is not limited in their rights. That user is automatically made a member of the group sudo and is allowed to run any command as root by using the sudo program. This means you can make use of sudo to do anything you want on the system, even to run whole shells and other programs as root, as SteveInBavaria pointed out.

Ubuntu is slightly different from many other Linux distros in its approach, because it disables logging in as root by not setting a password for root. On many Linux systems, when you want to elevate privileges, you become the root user by typing su — or just su in a terminal. The su (switch user) command allows you to log in as another user in a shell. You must enter the password of the user you want to log in as, not your own password. On Ubuntu su fails because root has no password. You can «fix» this by setting a password for root, but this is discouraged and not necessary since sudo provides all privileges. You can even run the su command as root by typing sudo su . Then you type your own password and become root. However, since sudo provides a way to open a root shell there is no need to run the su program with it for this purpose. You can simply use sudo -i .

Читайте также:  Ssd and linux ubuntu

Источник

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 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.

Читайте также:  Linux скопировать все файлы txt

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.

Источник

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.

Читайте также:  Linux проверить обновления пакетов

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.

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