You are not logged in.
Pages: 1
How can I add a user to a group through the command line? I want to do this in a shelll script... I know you can edit /etc/groups, but I want to know the command line command for it...
If I have the gift of prophecy and can fathom all mysteries and all knowledge, and if I have a faith that can move mountains, but have not love, I am nothing. 1 Corinthians 13:2
Offline
gpasswd -a user group
Offline
try "man usermod"
to add:
# user to edit and his new group
USERNAME="phrakture"
NEWGROUP="sound"
# create a comma delimited list of users
GROUPS=`groups $USERNAME | sed -e s/ /,/g`
usermod $USERNAME -G $GROUPS,$NEWGROUP
and to remove:
# user to edit and his new group
USERNAME="phrakture"
OLDGROUP="sound"
# create a comma delimited list of users
GROUPS=`groups $USERNAME | sed -e s/$OLDGROUP//g | sed -e s/ /,/g`
usermod $USERNAME -G $GROUPS
now, one minor error here - in the remove script, if the group to be removed is last in the list, the list will end with a comma... I don't know if this will error out or not
Offline
gpasswd -a user group
hmmm, yes, however this requires group admin rights....
but mine is still more fun 8)
Offline
thanks all, exactly what i was looking for
If I have the gift of prophecy and can fathom all mysteries and all knowledge, and if I have a faith that can move mountains, but have not love, I am nothing. 1 Corinthians 13:2
Offline
Pages: 1