Segfault > IT > Lookups > Manage users in Linux

 

  • To know which users exist:
    cat /etc/passwd | grep -i home
  • Delete a user:
    userdel [username]
  • Add a user:
    useradd -m [username] (the "-m" flag creates the home directory)
  • Set the user's password:
    passwd [username]
  • Assign a user to a group:
    usermod -a -G [groupname] [username]
    (make the user re-login to activate the changes)
    (for a user to be able to "su" to another one, it has to be in the group "wheel")
  • View to which groups a user was assigned:
    groups [username]
  • Remove a group from a user:
    usermod -G [all_groups_the_user_is_supposed_to_have-comma_separated] [username]
    Here I practically reassign to the user only the groups listed and the rest gets deleted.
    (make the user re-login to activate the changes)
  • Change the owner of a file:
    chown [newowner] [filename]
  • Change the assigned group of a file:
    chgrp [newgroup] [filename]
  • Create a group:
    groupadd [newgroup]
    Now you can assign files and users to the new group.
  • Delete a group:
    groupdel [groupname]