Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place! |
Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
|
11-25-2005, 08:42 AM
|
#1
|
LQ Newbie
Registered: Oct 2004
Posts: 2
Rep:
|
How to list user in Linux box, add an user to a group!
I have found for time but i still don' know how to list the user in my linux box, also how can I add an exist user to a group!
|
|
|
Click here to see the post LQ members have rated as the most helpful post in this thread.
|
11-25-2005, 09:26 AM
|
#2
|
Member
Registered: Nov 2003
Location: Bristol, UK
Distribution: Debian Lenny, Gentoo (at work)
Posts: 388
Rep:
|
To list the users:
cat /etc/passwd | cut -d":" -f1
Hmm, not sure about how to add an existing user to a group though.
|
|
|
11-25-2005, 09:38 AM
|
#3
|
Senior Member
Registered: Jul 2004
Location: Skuttunge SWEDEN
Distribution: Debian preferably
Posts: 1,350
Rep:
|
Depending on distro and desktop, you probably have several gui's to choose from.
Search the menu, or systems control-center (if any), or kde's controlcenter.
Or do it the manual way:
List users:
# cat /etc/passwd
Add user to a group: edit /etc/group Syntax is:
cdrom:x:22 eterh,charles
The user of course has to exist or you'll have problems...
Command-line tools:
useradd and groupadd
|
|
|
11-25-2005, 08:29 PM
|
#4
|
LQ Newbie
Registered: Oct 2004
Posts: 2
Original Poster
Rep:
|
Re: How to list user in Linux box, add an user to a group!
Quote:
Originally posted by steady_lfcfan
I have found for time but i still don' know how to list the user in my linux box, also how can I add an exist user to a group!
|
thank you, but this print all user includes system user (samba,apache ...)
Pingu, I am running Radhat box and I have not X installed, is there other way?
|
|
|
11-26-2005, 12:30 AM
|
#5
|
Member
Registered: Oct 2002
Distribution: Debian 6.0.2 (squeeze)
Posts: 944
Rep:
|
|
|
|
11-26-2005, 12:51 AM
|
#6
|
LQ Veteran
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,286
|
Re: How to list user in Linux box, add an user to a group!
Quote:
Originally posted by steady_lfcfan
... also how can I add an exist user to a group!
|
"usermod -G ..." ???
See the manpage.
|
|
|
01-16-2008, 08:12 AM
|
#7
|
LQ Newbie
Registered: Jan 2008
Posts: 1
Rep:
|
well I see many answered to the listing users,but not so clear answers to adding an existing user to a group (no offense); you can do this by using the "gpasswd -a user group" command.
I know my answer is only a few years late but for googling people it might be nice
Last edited by fr4X; 01-16-2008 at 08:14 AM.
|
|
2 members found this post helpful.
|
01-23-2008, 02:46 AM
|
#8
|
LQ Newbie
Registered: Jan 2008
Posts: 2
Rep:
|
As long as the thread got drug up...
Quote:
Originally Posted by syg00
"usermod -G ..." ???
See the manpage.
|
That's dangerous, since it will REMOVE the user from all current groups and put them ONLY in the specified groups.
Quote:
Originally Posted by manpage
-G, --groups GROUP1[,GROUP2,...[,GROUPN]]]
A list of supplementary groups which the user is also a member of.
Each group is separated from the next by a comma, with no
intervening whitespace. The groups are subject to the same
restrictions as the group given with the -g option. If the user is
currently a member of a group which is not listed, the user will be
removed from the group. This behaviour can be changed via the -a
option, which appends the user to the current supplementary group
list.
|
Be sure to do -aG, not just -G.
|
|
|
07-26-2009, 12:54 PM
|
#9
|
LQ Newbie
Registered: Jul 2009
Posts: 1
Rep:
|
Listing Groups
For those following along at home, listing groups can be accomplished in the same way as users:
Code:
cat /etc/group | cut -d":" -f1
|
|
|
01-26-2010, 03:39 PM
|
#10
|
LQ Newbie
Registered: Jan 2010
Posts: 1
Rep:
|
Quote:
Originally Posted by steady_lfcfan
thank you, but this print all user includes system user (samba,apache ...)
|
You will want to search for UIDs in the /etc/passwd file that are greater than 999. The first user account will have the UID 1000, so any account greater than 999 should not be a system account. I recently had to add the group sftponly to a all GIDs above 1000 (so as not to include my own UID on the system). You will want to replace the number 1000 with the starting UID that you want to update and change sftponly to the group name that you want to add. Here is the command that I ran:
Code:
awk -F: '$3 > 1000 {print $1}' /etc/passwd | xargs -I USERNAME sudo usermod -a -G sftponly USERNAME
|
|
|
05-03-2010, 04:52 AM
|
#11
|
LQ Newbie
Registered: Aug 2009
Posts: 5
Rep:
|
Quote:
Originally Posted by B-Con
As long as the thread got drug up...
That's dangerous, since it will REMOVE the user from all current groups and put them ONLY in the specified groups.
Be sure to do -aG, not just -G.
|
I tried 'usermod -aG' (at SLES 10, SLES 11), the error comes with:
usermod: invalid option -- 'a'
I tried another option and it works. Since I cannot get any manual/manpage/help about it, you may try it by using non-important user_name first:
usermod -A Group1 user_name
, which adds an existing user 'user_name' to an existing group 'Group1' without changing the group list the user belongs to.
Last edited by Weining; 05-03-2010 at 05:29 AM.
|
|
|
09-14-2012, 10:18 AM
|
#12
|
LQ Newbie
Registered: Aug 2012
Posts: 6
Rep:
|
Bash script to display the detailed user information in Linux
A very useful bash script to display the detailed user information in Linux
<moderated>
Last edited by colucix; 10-20-2012 at 09:45 AM.
Reason: Driving traffic to your own blog is not allowed at LQ!
|
|
|
01-27-2013, 02:14 PM
|
#13
|
Member
Registered: Feb 2005
Location: Texas, USA
Distribution: opensuse
Posts: 106
Rep:
|
Quote:
Originally Posted by trevelluk
To list the users:
cat /etc/passwd | cut -d":" -f1
Hmm, not sure about how to add an existing user to a group though.
|
# usermod -G {group-name} username
in SuSE linux, there is No -a (this article states that the '-a' retains existing groups and 'adds' new group '-G'), but in openSuSE 12.2, there is no '-a' option to usermod, it keeps existing groups by default, i guess...
Code:
# id lunar
uid=1002(lunar) gid=100(users) groups=100(users)
# usermod -G sshd lunar
# id lunar
uid=1002(lunar) gid=100(users) groups=100(users),102(sshd)
#
Landis.
|
|
|
All times are GMT -5. The time now is 04:04 AM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|