Wiki source code of How to Add User to Sudoers in Debian
Last modified by René Schmidt on 2023/09/27 14:12
Hide last authors
| author | version | line-number | content |
|---|---|---|---|
![]() |
1.1 | 1 | (% class="jumbotron" %) |
| 2 | ((( | ||
| 3 | (% class="container" %) | ||
| 4 | ((( | ||
| 5 | = How to Add User to Sudoers in Debian = | ||
| 6 | |||
| 7 | Sudo (for superuser do) is a command-line utility that allows users to run commands with root privileges. | ||
| 8 | |||
| 9 | It gives users admin-level permissions to run programs on your machine. | ||
| 10 | |||
| 11 | Using sudo is more secure than opening a session as root. The root password is protected as sudo prompts for the current user's password. | ||
| 12 | |||
| 13 | You can temporarily grant extra privileges to users. The access is removed without changing any password. | ||
| 14 | |||
| 15 | This tutorial covers **how to add a new user to sudoers** in the Debian Linux system. | ||
| 16 | ))) | ||
| 17 | ))) | ||
| 18 | |||
| 19 | (% class="row" %) | ||
| 20 | ((( | ||
| 21 | (% class="col-xs-12 col-sm-8" %) | ||
| 22 | ((( | ||
| 23 | == Steps to Add Sudoers in Debian == | ||
| 24 | |||
| 25 | === 1. Log in as the Root User === | ||
| 26 | |||
| 27 | Before adding a user to your system, log in to your server as the root user: | ||
| 28 | |||
| 29 | (% class="box" %) | ||
| 30 | ((( | ||
| 31 | ssh root@ip_address | ||
| 32 | ))) | ||
| 33 | |||
| 34 | In the above line, replace ip_address with the IP address of your server. | ||
| 35 | |||
| 36 | === 2. Add a New User in Debian === | ||
| 37 | |||
| 38 | You can create a new user with the adduser command as a root user. Append the required user account name to the [[SSH>>url:https://www.cloudpanel.io/tutorial/set-up-ssh-keys-on-ubuntu-20-04/]] command: | ||
| 39 | |||
| 40 | (% class="box" %) | ||
| 41 | ((( | ||
| 42 | adduser username | ||
| 43 | ))) | ||
| 44 | |||
| 45 | For example, add a new account sudo_user with the command: | ||
| 46 | |||
| 47 | (% class="box" %) | ||
| 48 | ((( | ||
| 49 | adduser sudo_user | ||
| 50 | ))) | ||
| 51 | |||
| 52 | The output looks like this: | ||
| 53 | |||
| 54 | [[image:https://www.cloudpanel.io/astatic/assets/images/article/2022/64/50df807eeda7e0ce8d87d3cf8d503403.png||alt="How to Add User to Sudoers in Debian"]] | ||
| 55 | |||
| 56 | The sudo command creates a home directory for the user and copies all the necessary files. | ||
| 57 | |||
| 58 | Enter the password for the user account and retype to confirm it. | ||
| 59 | |||
| 60 | Set a strong password for accounts with sudo access. | ||
| 61 | |||
| 62 | [[image:https://www.cloudpanel.io/astatic/assets/images/article/2022/64/925e0d017b3ad56ebfc346dce6842f01.png||alt="Set a strong password -How to Add User to Sudoers in Debian"]] | ||
| 63 | |||
| 64 | In the terminal, you will be prompted to change the user information. | ||
| 65 | |||
| 66 | Add the details in the text editor or press Enter to leave the fields blank. | ||
| 67 | |||
| 68 | [[image:https://www.cloudpanel.io/astatic/assets/images/article/2022/64/c40b415fc2522ed304f46289606f2903.png||alt="How to Add User to Sudoers in Debian"]] | ||
| 69 | |||
| 70 | === 3. Add User to the Sudo Group === | ||
| 71 | |||
| 72 | Users that have root privileges can add any account to the sudo group. | ||
| 73 | |||
| 74 | Everyone in the group automatically gets sudo access to Debian and Ubuntu operating systems. | ||
| 75 | |||
| 76 | Run the command shown below and add a user to the sudo group: | ||
| 77 | |||
| 78 | (% class="box" %) | ||
| 79 | ((( | ||
| 80 | usermod -aG sudo username | ||
| 81 | ))) | ||
| 82 | |||
| 83 | The [[commands>>url:https://www.cloudpanel.io/docs/v2/cloudpanel-cli/root-user-commands/]] consists of the following components: | ||
| 84 | |||
| 85 | * **usermod** command modifies a user account. | ||
| 86 | * **-aG** is an option that adds the user to a specific group. The **-a option** adds a user to the group. It does that without removing them from the current groups. The **-G option** is used to state where to add the existing user. | ||
| 87 | * sudo is the group that is appended to the options mentioned above. | ||
| 88 | * **username** is the user account you want to add to the sudo group. | ||
| 89 | |||
| 90 | Verify the new Debian sudo user is added to the group with the command: | ||
| 91 | |||
| 92 | (% class="box" %) | ||
| 93 | ((( | ||
| 94 | getent group sudo | ||
| 95 | ))) | ||
| 96 | |||
| 97 | The output lists all users in the group. | ||
| 98 | |||
| 99 | [[image:https://www.cloudpanel.io/astatic/assets/images/article/2022/64/847794fec5b04868e395f0cb1130bb42.png||alt="How to Add User to Sudoers in Debian"]] | ||
| 100 | |||
| 101 | === 4. Verify Sudo Access in Debian === | ||
| 102 | |||
| 103 | To verify the new user has sudo privileges: | ||
| 104 | |||
| 105 | * ((( | ||
| 106 | Switch to the user account you have created. You can do it by running the command shown below. | ||
| 107 | |||
| 108 | You have to replace the username with the name of your user account- | ||
| 109 | ))) | ||
| 110 | |||
| 111 | (% class="box" %) | ||
| 112 | ((( | ||
| 113 | su - username | ||
| 114 | ))) | ||
| 115 | |||
| 116 | Run a command that requires superuser access. For example, sudo whoami will show you that you are the root. | ||
| 117 | |||
| 118 | |||
| 119 | === 5. Using Sudo === | ||
| 120 | |||
| 121 | If you want to run a command with root access, type in sudo and enter the required command. | ||
| 122 | |||
| 123 | For example, you can view details for the root directory, run the ls tool as the following - | ||
| 124 | |||
| 125 | (% class="box" %) | ||
| 126 | ((( | ||
| 127 | sudo ls -la /root | ||
| 128 | ))) | ||
| 129 | |||
| 130 | Enter the user’s password as prompted. The terminal will show the contents of the root directory. | ||
| 131 | |||
| 132 | You only have to enter the password once for the same session. | ||
| 133 | |||
| 134 | == Summary == | ||
| 135 | |||
| 136 | **Sudo** allows individual users to run commands that require special privileges, such as **linux make user admin** or **debian useradd**. This can be particularly useful when you need to **make a user sudo**, **grant sudo privileges**, or allow a user to run specific **sudo commands** on systems like Ubuntu. | ||
| 137 | |||
| 138 | You can revoke access easily after you execute the commands as a root account by editing the **sudoers file**. Debian's default configuration allows users in the sudo group to run any command via sudo, making it easy for an Ubuntu make user admin or ad user to sudo. | ||
| 139 | ))) | ||
| 140 | |||
| 141 | |||
| 142 | (% class="col-xs-12 col-sm-4" %) | ||
| 143 | ((( | ||
| 144 | {{box title="**Contents**"}} | ||
| 145 | {{toc/}} | ||
| 146 | {{/box}} | ||
| 147 | |||
| 148 | [[image:Templates.Article.Template.WebHome@image1.jpg]] | ||
| 149 | //Figure 1: [[Sea>>https://commons.wikimedia.org/wiki/File:Isle_of_Icacos_II.jpg]]// | ||
| 150 | |||
| 151 | [[image:Templates.Article.Template.WebHome@image2.jpg]] | ||
| 152 | //Figure 2: [[Waves>>https://commons.wikimedia.org/wiki/File:Culebra_-_Playa_de_Flamenco.jpg]]// | ||
| 153 | ))) | ||
| 154 | ))) |
