Previous

How to Manage Users on a Linux Server via SSH

Next

How to Manage Users on a Linux Server via SSH

1. Accessing Your Server via SSH

To begin managing your server, you'll first need to establish a secure connection using SSH (Secure Shell).

ssh username@IPaddress
Best Practice: For enhanced security, consider using SSH keys instead of password authentication.

2. Creating a New User

Once logged in, you can create a new user with the adduser command:

sudo adduser newusername       

Complete example with output:

root@dummy:~# adduser ram
Adding user `ram` ...
Selecting UID/GID from range 1000 to 59999 ...
Adding new group `ram` (1001) ...
Adding new user `ram` (1001) with group `ram (1001)` ...
Creating home directory `/home/ram` ...
Copying files from `/etc/skel` ...

New password:
Retype new password:
passwd: password updated successfully

Changing the user information for ram
Enter the new value, or press ENTER for the default
        Full Name []: Ram Kumar
        Room Number []: 
        Work Phone []: 
        Home Phone []: 
        Other []: 
Is the information correct? [Y/n] Y

Adding new user `ram` to supplemental groups `users` ...
Adding user `ram` to group `users` ...       

3. Granting Administrative Privileges

To allow your new user to perform administrative tasks, add them to the sudo group:

sudo usermod -aG sudo username

4. Switching to the New User

To verify your new user account works properly, switch to it using:

su - username    

5. Additional User Management Commands

Change user password:

sudo passwd username

Delete a user:

sudo deluser username

Delete user including home directory:

sudo deluser --remove-home username

List all users:

cut -d: -f1 /etc/passwd