Hi, I'm Ataias Reis

Programmer, made in Brazil, Alma mater University of Brasilia

More admin commands for users in Linux

This post is a collection of commands basically, I hope it works a reference for me and other people who pass by.

To delete users, we have deluser and userdel. For me, it was really weird learning that we have two commands with similar names that basically do the same thing. I present some examples below.

# removes user and home directory
$ deluser -r user
$ userdel user
# remover user from group
$ deluser user group
# deleting a group
$ deluser --group group

Creating or deleting groups, adding a user to them or changing primary group:

# creates group
$ groupadd groupname
# adds user to group
$ gpasswd -a username groupname
# removes a user from a group
$ gpasswd -d username groupname
# remove a group
$ groupdel groupname
# remove a user from group
$ delgroup username groupname
# change primary user group
$ usermod -g othergroup username
# check groups of an user
$ groups username

Changing the group of a file/folder:

# change group of a file or folder
$ chgrp group file/folder
# changing recursively (all inner files too)
$ chgrp -R group folder
# changing the user of a file/folder
$ chown user file
# changing folder and recursively
$ chown -R user folder
# changing user and group for a folder
# recursively
$ chown -R user:group folder

Hopefully this was useful for you guys. Let me know if you have any suggestions. Thanks for reading!

Tags
comments powered by Disqus