Friday, 20 May 2011

Basic Linux commands – Part III. Managing Users and Groups

This should be a short post. FTP and Email users will be stored in MySQL databases so you will not need to add too many users, change their passwords, remove them, etc.  You will need to create some users eventually so let’s see how it’s done.

groupadd - Create a new group
groupadd -g 5099 myGroup
This will create a new group called myGroup with Group ID (GID) 5099.

useradd - Create a new user
useradd -u 5099 -g myGroup -s /sbin/nologin -d /home/myUser_home_dir myUser
This will create a new user called myUser with User ID (UID) 5099 with home directory “/home/myUser_home_dir”.
While both UID and GID are 5099 they could have been different.

groupdel - Delete a group
groupdel myGroup
This will delete the group called myGroup. You may not remove the primary group of any existing user. Delete myUser before you delete myGroup.

userdel - Delete a user
userdel -r myUser
This will delete the user called myUser and it’s home directory (that’s what -r option does).
Don’t delete it before you test the commands below :)

usermod - Modify an existing user
usermod -G mail myUser
This will add mail as a secondary group for myUser.
You can use this command to change home directory and shell too.

id - Get information for an existing user
id myUser
This will display user’s UID, GID and secondary groups.

passwd - Change user’s password
passwd myUser
You will be asked to enter the new password.

chmod - Change file access permissions
chmod 644 -R /home/myUser_home_dir
Change permission to “/home/myUser_home_dir” and all its files recursively.

chown - Change file owner and group
chown myUser:myGroup -R /home/myUser_home_dir
Change the owner and group to ftpuser / ftpgroup for  “/home/myUser_home_dir” and all its files recursively.

File permissions
644, 755, 777, 750? This post is not about file permissions. If I’ll add one I will post the link here :)

No comments:

Post a Comment