Creating a New User on Ubuntu Server 24
Creating users is one of the first tasks on any fresh Ubuntu Server β and the place where a careless sudo grant can haunt you later. This is the sequence I use on Ubuntu Server 24: create the user, grant privileges only when they're actually needed, and verify the account works before moving on.
π» Step 1: Access the terminal
If you're working directly on the server, you're already there. Remotely, log in over SSH:
BASHssh your-username@your-server-ip
π€ Step 2: Create the user
adduser is the friendlier of Ubuntu's user-creation commands β it creates the home directory, sets the shell, and prompts for the details interactively:
BASHsudo adduser newuser
You'll be asked to:
- Enter and confirm a password for the new user.
- Fill in optional details (Full Name, Room Number, and so on) β press Enter to skip any of them.
π Step 3: Grant administrative privileges (only if needed)
On Ubuntu, membership in the sudo group is what grants admin rights. Skip this step unless the user genuinely needs it β most day-to-day and service accounts don't:
BASHsudo usermod -aG sudo newuser
usermodβ modifies an existing user account.-aGβ appends the user to a group. The-amatters:-Gon its own replaces the user's entire group list instead of adding to it.sudoβ the group that grants administrative permissions.
β Step 4: Verify
Check that the home directory exists:
BASHls /home
Then switch to the account and confirm the password works:
BASHsu - newuser
If you granted sudo, verify that too with sudo -v while logged in as the new user.
π Useful commands for later
-
Delete a user:
BASHsudo deluser newuserOr delete the home directory along with it:
BASHsudo deluser --remove-home newuser -
Change a user's password:
BASHsudo passwd newuser -
View a user's UID, GID, and group memberships:
BASHid newuser
π Conclusion
That's a working, verified user account β with elevated privileges only if you deliberately granted them. From here, the natural next step is setting up SSH key access for the new user instead of relying on passwords.
Happy coding π