Skip to content

Instantly share code, notes, and snippets.

@rohitfarmer
Last active June 28, 2023 19:14
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
User management and file permission in Linux

User management

Add a new user

The command below will add a new user to a Linux system, create their home directory at /home/newuser and set the default shell to /bin/bash.

sudo useradd -m -s /bin/bash newuser

The command below set the password for the new user.

sudo passwd newuser

Delete a user

The command below will delete a user without deleting their home directory.

sudo userdel newuser

To delete the home directory as well.

sudo userdel --remove newuser

Login as another user

To login as a newly created user

sudo -u newuser bash

Add an existing user to a group

sudo usermod -a -G groupname newuser
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment