LightYear
/Docs
DocsSecurityCreate a Non-Root User with Sudo Privileges

Create a Non-Root User with Sudo Privileges

Create a regular user account with sudo access as a security best practice for server management.

beginner
5 min read
LightYear Docs Team
Updated April 24, 2026
userssudosecuritylinuxbest-practices
Ready to get started?

Running all commands as root is a security risk. A mistake as root can cause irreversible damage. This guide creates a non-root user with sudo privileges for day-to-day server management.

Step 1 — Create the User

>_BASH
$adduser deploy
OUTPUT
Adding user 'deploy' ...
Adding new group 'deploy' (1001) ...
Adding new user 'deploy' (1001) with group 'deploy' ...
Creating home directory '/home/deploy' ...
New password:
Retype new password:
passwd: password updated successfully
Full Name []: Deploy User
Room Number []:
Work Phone []:
Home Phone []:
Other []:
Is the information correct? [Y/n] Y

Step 2 — Grant Sudo Privileges

>_BASH
$usermod -aG sudo deploy

Verify the group membership:

>_BASH
$groups deploy
OUTPUT
deploy : deploy sudo

Step 3 — Copy SSH Key to the New User

>_BASH
$rsync --archive --chown=deploy:deploy ~/.ssh /home/deploy

Verify the key was copied:

>_BASH
$ls -la /home/deploy/.ssh/
OUTPUT
total 16
drwx------ 2 deploy deploy 4096 Apr 24 10:00 .
drwxr-xr-x 3 deploy deploy 4096 Apr 24 10:00 ..
-rw------- 1 deploy deploy  571 Apr 24 10:00 authorized_keys

Step 4 — Test the New User

Open a new terminal and test the connection:

>_BASH
$ssh deploy@YOUR_SERVER_IP

Test sudo access:

>_BASH
$sudo apt update
OUTPUT
[sudo] password for deploy:
Hit:1 http://archive.ubuntu.com/ubuntu jammy InRelease

Step 5 — Disable Root Login

Once you have confirmed the new user works, disable root SSH login:

>_BASH
$sudo nano /etc/ssh/sshd_config
INI
PermitRootLogin no
>_BASH
$sudo systemctl restart sshd

[!IMPORTANT] Always test the new user in a separate terminal before disabling root login. If you lock yourself out, you will need to use the LightYear console to regain access.

Was this article helpful?

Your cookie choices for this website

This site uses cookies and related technologies, as described in our privacy policy, for purposes that may include site operation, analytics, and enhanced user experience. You may choose to consent to our use of these technologies, or manage your own preferences. Cookie policy