Thursday, July 7, 2011

Managing Users from the command line

Adding groups and accounts:
Adding accounts from the command line is not as easy as using the ls command. Because the commands used, useradd and groupadd, is not part of the default PATH variable. To use the command you can; first use the, export PATH=$PATH: /usr/sbin. This will ad the PATH for the active session. Or you could add the export command to .bashrc, a hidden file that is automatic run every time you run the bash sell. I will use the second option in this tutorial.

$ su
$ nano .bashrc
add the, export PATH=$PATH:/usr/sbin, at the bottom of the file and save/exit
$ groupadd testgroup
$ useradd -G testgroup -c "test user" \
>testuser
$ passwd testuser

-G flag adds testuser to testgroup, -c gives full name. When we create new users the passwords are locked so you use the passwd and user to assign a password for that user.

Deleting accounts and groups:
Its basically the same format as creating groups and users. You use the commands, userdel and groupdel. One must love the simplicity of Linux =) Note however that the users home directory is intact; you might want to delete this directory as root.

$ su
$ groupdel testgroup
$ userdel testuser
$ rm -rf /home/testuser/

No comments:

Post a Comment