Add user account on Ubuntu
useradd <username>
The following command line will create the user named testuser and give them their own home directory in /home/testuser. The files in the new home directory are copied from the /etc/skel folder, which contains default home directory files. If you wanted to set default values for your users, you would do so by modifying or adding files in that directory.
sudo useradd -d /home/testuser -m testuser
sudo passwd testuser
If we take a look at the new home directory for the
user:geek@ubuntuServ:/etc/skel$ ls -la /home/testuser
total 20
drwxr-xr-x 2 testuser testuser 4096 2006-12-15 11:34 .
drwxr-xr-x 5 root root 4096 2006-12-15 11:37 ..
-rw-r–r– 1 testuser testuser 220 2006-12-15 11:34 .bash_logout
-rw-r–r– 1 testuser testuser 414 2006-12-15 11:34 .bash_profile
-rw-r–r– 1 testuser testuser 2227 2006-12-15 11:34 .bashrc
You’ll notice that there are bash scripts in this directory. If you wanted to set default path options for all new users, you would do so by modifying the files in /etc/skel, which would then be used to create these files by the useradd command.
Setup password for user
# passwd <username>
Add group
groupadd <groupname>
Add user to group
useradd -G <groupname> <username>
Ensure user added properly to group developers
# id
output
uid=1122(vivek) gid=1125(vivek) groups=1125(vivek),1124(developers)
Please note that capital G (-G) option add user to a list of supplementary groups. Each group is separated from the next by a comma, with no intervening whitespace. For example, add user jerry to groups admins, ftp, www, and developers, enter:
# useradd -G admins,ftp,www,developers jerry
useradd example – Add a new user to primary group
To add a user tony to group developers use following command:
# useradd -g developers tony
# id tony
Sample outputs:
uid=1123(tony) gid=1124(developers) groups=1124(developers)
Please note that small -g option add user to initial login group (primary group). The group name must exist. A group number must refer to an already existing group.
usermod example – Add a existing user to existing group
Add existing user tony to ftp supplementary/secondary group with usermod command using -a option ~ i.e. add the user to the supplemental group(s). Use only with -G option :
# usermod -a -G ftp tony
Change existing user tony primary group to www:
# usermod -g www tony
Remove a user from a group
deluser <username> <groupname>
Remove a user account
# userdel <username>
# userdel -r <username>
-r option will remove the user’s home directory as well.
File to check users and groups:
/etc/passwd
/etc/group
use command to see users and user information
# cat /etc/passwd (vi /ect/passwd)
or
# lastlog
Add a User
- add user on Linux Server: take nina as a example
- add nina to www group password: ninatang
- useradd -g www nina
- vi ninapas
- nina:ninatang
- chpasswd < ninapas
- change group the user belong to: usermod -g newgroup nina
See Which Groups Your Linux User Belongs To
When you are using a linux system, it’s useful to find out what groups you belong to, so you can understand whether you have access to files and directories. This is one of the simplest commands possible. I’m using Ubuntu linux, but this command should work on most varieties of linux.
groups <username>
If you don’t enter a username, it defaults to your own username. For instance:
geek@ubuntuServ:$ groups
geek adm dialout cdrom floppy audio dip video plugdev lpadmin scanner admin fuse
You can also check the groups for any other user, including root:
geek@ubuntuServ:$ groups root
root : root fuse
I used this command recently to make sure that my user account was part of the “fuse” group, when I was getting sshfs set up. Very useful.
http://www.howtogeek.com/howto/ubuntu/see-which-groups-your-linux-user-belongs-to/