Wednesday 4 March 2015

how to Add,delete,modify user in ubuntu



A command to list all users? And how to add, delete, modify users?

 ____________________________________________________________________________


I need a command to list all users in terminal. And how to add, delete, modify users from terminal.

That could help in administrating your accounts easily by terminal.


 


Answers:

To list all users you can use:
cut -d: -f1 /etc/passwd
To add a new user you can use:
sudo adduser new_username
or:

sudo useradd new_username
...............................................................................................................

To remove/delete a user, first you can use:
sudo userdel username
Then you may want to delete the home directory for the deleted user account :
sudo rm -r /home/username

(Please use with caution the above command!)
To modify the username of a user:
usermod -l new_username old_username

To change the password for a user:
sudo passwd username

To change the shell for a user:
sudo chsh username

To change the details for a user (for example real name):
sudo chfn username
And, of course, see also: man adduser, man useradd, man userdel... and so on.




...................................................................................................................................................................


Just press Ctrl+Alt+T on your keyboard to open Terminal. When it opens, run the command(s) below:

cat /etc/passwd
OR
less /etc/passwd
more /etc/passwd

You can also use awk:
awk -F':' '{ print $1}' /etc/passwd


.............................................................................................................


To get a list of all users you type (as users are listed in /etc/passwd)
getent passwd

To add a user newuser to the system you would type
sudo adduser newuser

to create a user that has all default settings applied.
Bonus: To add any user (for instance anyuser) to a group (for instance cdrom) type
sudo adduser anyuser cdrom

You delete a user (for instance obsolete) with
sudo deluser obsolete

If you want to delete his home directory/mails as well you type
sudo deluser --remove-home obsolete

And
sudo deluser --remove-all-files obsolete

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







user (tab tab)

gives me as possible options useradd userdel usermod users users-admin
if you want to know more about a command google it or type man man useradd gives useradd - create a new user or update default new user information ... ...
to list users you should go with what Mitch said.
Hope that helps I love tab completion in bash saves me from remembering things.
--------------------------------------------------------------------------------------------------------


 --------------------------------------------------------------------------------------------------------
list of all users who can login (no system users like: bin,deamon,mail,sys, etc.)
awk -F':' '$2 ~ "\$" {print $1}' /etc/shadow
add new user
sudo adduser new_username
 or
 sudo useradd new_username

delete/remove username
sudo userdel username
If you want to delete the home directory (default the directory /home/username)

sudo deluser --remove-home username
or
sudo rm -r /path/to/user_home_dir

If you want to delete all files from the system from this user (not only is the home diretory)

sudo deluser --remove-all-files



To find out the users on the server, run the following commands
cd /home ls
You can then see the users who have authorization to log into the server. If we want to look into the files of any users, you must be the root user.









0 comments:

Post a Comment

Copyright © 2014 Network Support Solution | Designed With By Blogger Templates
Scroll To Top