Saturday 11 June 2011

Create, delete, and modify local user accounts

Another reasonably simple objective:

Create user accounts:

By default when creating users in Red Hat a group with the username will also be created and this will be the main group for the user, with a group id higher than 500. To create a user in this way, and also accepting all other defaults (create user directory, bash as the user shell, etc) simply do:
useradd username
 You can check that a new group has also been created:
getent group | grep username
 Alternatively, you can assign the user to an already existing group:
useradd -g groupname username
There are quite a number of options when creating users, so have a look at them.

Delete user accounts:

This one is fairly simple:
userdel -r username
Note that this will remove the home directory and mail spool for the user, if you want the directory and mail spool to remain, just user:
userdel username
Modify user accounts:

The command used to modify accounts, usermod, is very similar to the one used to add them. Say you want to change the user's shell:
usermod -s /bin/sh username
or make the user member of a couple of extra secondary groups:
usermod -aG groupname1,groupname2 username
 or change the username:
usermod -l newusername oldusername

No comments:

Post a Comment