Q. How do I add a user to a group under Sun Solaris UNIX operating system from a shell prompt or command line?
A.. You can useadd command to administer a new user login on the UNIX system. Solaris UNIX / HP-UX UNIX uses /etc/passwd, /etc/shadow and /etc/group files to store user information.
Following information is compatible with the Solaris, AIX and HP-UX UNIX operating systems.
Add A New User To A Group
Add a new user called vivek to a group called vsftp, enter:
# useradd -G vsftp -d /data/home/v/vivek -m vivek
# passwd vivek
Where,
- -G vsftp : Add vivek to secondary group called vsftp. This group must exists on the system.
- -d /data/home/v/vivek : Path to the vivek's home directory
- -m : Create the new user's home directory if it does not already exist.
- vivek : Username / login nane
UNIX Add Existing User To A Secondary Group
Use usermod command to modify a user's login definition on the system including group membership. For, example add user vivek to sales group, enter:
# usermod -G sales vivek
Add user tom to sales but also keep his existing membership of ftpusers, enter:
# usermod -G ftpusers,sales tom
UNIX Add Existing User To A Primary Group
Add jerry to sales primary group and change its existing group membership:
# usermod -g sales jerry
For more information read following man pages:
$ man usermod
$ man useradd
$ man passwd
You should follow me on twitter here or grab rss feed to keep track of new changes.
Featured Articles:
- 30 Handy Bash Shell Aliases For Linux / Unix / Mac OS X
- Top 30 Nmap Command Examples For Sys/Network Admins
- 25 PHP Security Best Practices For Sys Admins
- 20 Linux System Monitoring Tools Every SysAdmin Should Know
- 20 Linux Server Hardening Security Tips
- Linux: 20 Iptables Examples For New SysAdmins
- Top 20 OpenSSH Server Best Security Practices
- Top 20 Nginx WebServer Best Security Practices
- 20 Examples: Make Sure Unix / Linux Configuration Files Are Free From Syntax Errors
- 15 Greatest Open Source Terminal Applications Of 2012

- My 10 UNIX Command Line Mistakes
- Top 10 Open Source Web-Based Project Management Software
- Top 5 Email Client For Linux, Mac OS X, and Windows Users
- The Novice Guide To Buying A Linux Laptop





![Ubuntu: Rename an Account [ User ID ]](http://s13.cyberciti.org/images/shared/rp/3/30.jpg)







{ 21 comments… read them below or add one }
Hello Vivek,
I don’t want my private files to be displayed in the output of find command????
How do i hide my confidential files to be isolated from find output??
I am using RHEL 5
Mihir G joshi
Find is a command that is used to list all files that it “finds”. If you don’t want other people to find them when using find make sure they do not have root access or access to the directory in which the files are stored.
Usually on a multi-user system you would store your files in your home directory. The only users that have access to this directory are yourself, root and in general anyone who is a member of the group named after your username. Be aware that if you create users the hard way (by editting /etc/passwd /etc/shadow /etc/groups) and you create users with the same uid / gid then these will also be able to access because they are the “same” user.
Of course as a RHEL 5 owner you can indeed ask this sort of question of RedHat’s support teams.
I hope this helps.
Hi,
Can someone help. Is it possible to add # infront of user loginname without vi to the password file. I have more than 50 users loginame to hide. Any command?
Thanks
I don’t get you, provide more info.
Vivek,
Example: i have account named esha and i want to add #esha without manually vi to password file.
Any possible way?
You wanna lock user account? If so use passwd itself:
passwd -l usernameTo unlock
passwd -u usernameno its cannot possiable ok
u have to create via useradd command
note: while creating the user , system will automatically created related configuration file ok
Thanks Vivek. Another one:
What is the SUN command to get directory full path for example for shortcut: $QERP_TOP.
hi
i have a problem…
Can I change the properties of the group?
What I mean is let say i have one admin group , it can edit and install the SW in the system, and at the same time, I have a user group , it can just use the SW but can’t install it. AS long as i add a account to the group, it automatically can have those priveledge according to the group properties.
Thanks
Willaim Lee
Hi vivek , first sorry about my english (I’mfrom Brazil) .
My problem is : add an existing user to a group without removing its existing group.
For example:
HP > /usr/sam/lbin/grpusrs -m -l ‘,user’ group
Linux > /usr/sbin/groupmod -A user group
AIX > chgrpmem -m + user group
When I use this one “/usr/local/bin/usermod -G group user” , it removes any other existing group.
Tks for your attention
Samuel
Hi,
I’m new to HPUX.
Let say I have existing id called Sysadmin which is a normal user. How do I upgrade this id to become root equivalent, and have all the permissions like root.
Tq
we cannot change the same id
but chenahe the id for chmod command
it root loogin u have to change the permissions for perticular user
using of chown command
Lyenna
By editing /etc/passwd and changing the ID (second field) to zero.
Bye
using of chmod command only
do n;t chage the in vi mode ok
drwxr-xr-x 2 asit ae 1024 Jul 8 16:03 00000010
How will I change the name user “asit” to “amit” and group “ae” to “pp” ?
Any unix command?
Thanks
Asit
sed ‘s/asit/amit/g’ /etc/passwd > /etc/passwd.tmp
sed ‘s/ae/pp/g’ /etc/passwd.tmp > /etc/passwd
pwck ( to check for password file errors )
This answer to asit pal, If you want to change your user name from asit to amit, you should execute the follwing command
usermod -l amit asit
for group its almost same groupmod -n pp ae
Hi I am new to HP Unix please help in L1 and L2 commands and please let me any test server is there online where is can practice
no
and u have to search the google only
To append a group to the user’s list of supplemental groups, include the ‘-a’ flag.
For example, to add user ‘popeye’ who is already in the ‘sailor’ group …
# groups popeye
popeye : popeye sailor
… to the ‘forearm’ group as well, you can do this:
# usermod -a -G forearm popeye
This way it appends him, and does not overwrite the other groups he is a part of:
# groups popeye
popeye : popeye sailor forearm
This saves you the hassle of having to write out all the other groups he needs to be a part of just to add him to another one.