gordon's note users and groups of linux

users and groups of linux

● add a user (新增使用者)
sudo useradd name

或是

sudo adduser name

 
範例:

sudo adduser --system --no-create-home --group yourusername

The –system flag (-r) will create a system user – one which does not have a password, a home dir and is unable to login.
Q 1st: –no-create-home is no need?
Q 2nd: –group is for what?
 

● modify the username of a user:
sudo usermod -l new_username old_username

 

● To change the password for a user:
sudo passwd username

 

● change the shell for a user:
sudo chsh username

 

● To change the details for a user (for example real name):
sudo chfn username

 

● remove/delete a user
sudo userdel username

 
Then to delete the home directory for the deleted user account:

sudo rm -r /home/username

 
Bonus: If you want to delete user’s home directory/mails as well

sudo deluser --remove-home username

and

sudo deluser --remove-all-files username

will remove the user and all files owned by this user on the whole system.
 

● list all the groups
cat /etc/group

 

● list all the groups of which the current user is a member
groups

 

● list the members of a group
getent group groupname

 

● add a user to a specific group use
sudo usermod -G groupname -a username

 

● remove a user from a specific group
sudo gpasswd -d username groupname

 

● delete a group
sudo groupdel groupname

 

 

 
#linux #user #adduser #removeuser #group #addgroup #removegroup

 

2015/3/15

Leave a Reply

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *