Centos usermod -a don't add a user to a group - linux

In my project i have to create a group on my centos server and add two users; i do:
sudo groupadd editorial
then i try to add my two users to group like this:
sudo usermod -a -G editorial nginx
sudo usermod -a -G editorial ec2-user
ok, no errors, but when i check my group:
sudo groups editorial
in output i get:
groups: editorial: no such user
why i cannot add my user to group?
Thanks in advance

Your form of the command is wrong. You separate the supplemental groups with commas not whitepsace, man usermod:
-G 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.
Example:
sudo usermod -a -G editorial,nginx nameofuser
And this questions is somewhat a close call, if you are writing a script to do this, then that is probably OK on StackOverflow, but if this is just a general "How do I use usermod", that should probably go to Super User or Unix & Linux

silly question.. but have you done "$sudo useradd nameofuser" before trying usermod?

Related

Linux command line: id, group and getent group not returning the same results

I'm wondering why I get different results from id and group on one hand, and getent group on the other. Steps to reproduce:
$ sudo usermod -a -G libvirt eric
$ groups
eric adm cdrom sudo dip plugdev lpadmin sambashare
$ id
uid=1000(eric) gid=1000(eric) groups=1000(eric),4(adm),24(cdrom),27(sudo),30(dip),46(plugdev),119(lpadmin),128(sambashare)
$ getent group | grep libvirt
libvirt:x:136:eric
libvirt-qemu:x:64055:libvirt-qemu
libvirt-dnsmasq:x:137:
The user eric is clearly a member of libvirt. Why doesn't this show up with id and group? Thanks.
System: Ubuntu Budgie 18.04 4.15.0-34-generic
If I remember correctly, you'd need to either log out and back in or run newgrp libvirt to make the new group ownership effective.

Problems with file ownership in a linux group

I have an ubuntu ec2 server.
I have a user, ubuntu created by aws for which I have the ssh key.
I have a team of 4 developers who have their own users and separate keys. Lets call them dev1, dev2, dev3, dev4.
Now I created a group called devs in which I added all 4 developer users. dev1 - dev4.
Problem I am facing is when dev1 upload/create a file via ftp on server machine, dev2 is not able to edit the file or upload another version of same file created by dev1, even though they are in same group, because its ownership lies with dev1.
How can I solve this problem. I want everyone in my group devs to be able to modify add or create files, in my /var/www/html/ folder, regardless of who created that file.
Can I give group ownership in linux be default? As far as I know ownership can always be with users not the group. Is there a simple and straightforward solution to this?
group structure -
You can see 4 users in group devs
The steps that you have to follow are:
Create the group:
sudo groupadd devs
Create the users:
sudo useradd dev1
sudo useradd dev2
sudo useradd dev3
sudo useradd dev4
Set a password for the users:
sudo passwd dev1
sudo passwd dev2
sudo passwd dev3
sudo passwd dev4
Insert the users in the "devs" group:
sudo usermod -a -G devs dev1
sudo usermod -a -G devs dev2
sudo usermod -a -G devs dev3
sudo usermod -a -G devs dev4
Check that the interested folder (/var/www/html) has the right permissions.
For example, I created 2 users (dev1 and dev2) for a test and inserted them in the group "devs". I created a file with the user "dev2".
These are the permissions:
rw-rw-r-- 1 dev2 devs 10 Sep 6 20:46 test.txt
The owner is "dev2" but the group is "devs". The permissions in my file for the group are "rw" (read/write) so, all the members of the group can read/write.
For more info about the linux file permissions: https://www.linux.com/learn/understanding-linux-file-permissions

When I(root) excute "usermod -G sudo chauncey",it say that "sudo group doesn't exist"

OS: CentOS 7. When I (root) execute the command below, it says that "sudo" group cannot be found.
[root#localhost etc]# usermod -G sudo chauncey
usermod:“sudo” group doesn't exits
I also check file in /etc/group, and "sudo" doesn't exists in it. So, how can I create a "sudo" group correctly?
In centos, you adduser to wheel group instead of sudo.
usermod - aG wheel username
Sudo is not directly a group. The groups/users having sudoer rights are defined in a configuration file that you can access using sudo visudo. Check out this file to find out how it is configured on your system. Here is a good introduction https://www.garron.me/en/linux/visudo-command-sudoers-file-sudo-default-editor.html.
In your case, you have different ways to give sudo rights to chauncey.
find the group(s) having sudo rights in the sudoers file and add chauncey to one of these groups. For example, say you have this line in sudoers:
# Members of the admin group may gain root privileges
%admin ALL=(ALL) ALL
then, add chauncey to admin with sudo usermod -a -G admin chauncey.
create a new sudo group (sudo groupadd sudo) and add this lines (sudo visudo). Then once again add chauncey to the group
# the 'sudo' group has all the sudo privileges
%sudo ALL=(ALL:ALL) ALL
set a special rule for this user in the sudoers file using the following (note that there is no %, which is used to denote a group):
chauncey ALL=(ALL:ALL) ALL
Note that for all the rules I mentioned, I used the default ALL everywhere. The first one is the user(s) allowed, the second one is the host, the third one is the user as you are running the command and the last one is the commands allowed. You can tune your rules if ALL is too broad for your usecase.

Linux Ubuntu 14.04.1 File Permissions

im really new to Linux permissions so I would appreciate help with this simple query.
Ubuntu 14.04.1
I have 2 users root and user1
I have a directory /var/www/html/gallery
The directory is empty
I would like to create a new group add root and user1 to that group and make that group have read, write and delete permissions(FULL PERMISSIONS), to the directory, /var/www/html/gallery
Can someone please help me ?
Thank you.
Root is usually not added to any group because root is allowed to do everything he or she wants.
So you have multiple options now:
1) you don't create a group and give the permissons to user1 (simplest solution)
chown -R user1:user1 /var/www/html/gallery
chmod -R 700 /var/www/html/gallery
2) you create the group anyways and just add one user. that just makes sense when you want to add some more users to the group later
you can use acl for permissions,
sudo apt-get install acl
sudo groupadd connoisseurs
sudo usermod -a -G connoisseurs Teddy
sudo setfacl -m g:connoisseurs:rwx /var/www/html/gallery
you can vary permissions with r,w,x combinations.

Add user to group but not reflected when run "id"

R creates a group called staff and I want to be able to update packages without starting R as sudo. So I added myself to staff using:
sudo usermod -G adm,dialout,cdrom,plugdev,lpadmin,admin,sambashare,staff matt
(side question is there a way to add yourself to a group without listing every other group you're a member of?)
If i check /etc/groups i see
staff:x:50:matt
and the same for /etc/shadow
staff:*::matt
however if i run groups or id i'm not a member of staff. Also, I can't make changes to anything in /usr/local/lib/R.
Did you log the "matt" account out and back in after running the sudo usermod command? Changes to the groups a user is in under unix only take affect at login time.
https://superuser.com/questions/272061/reload-a-linux-users-group-assignments-without-logging-out
check that out ~
both
newgrp groupname
OR
su - username
will do the trick well ~
In answer to your side question, yes you can add a user to a group without listing them all. If you run a Debian based system, you can do it with
sudo adduser matt staff
The adduser utility is just a friendly wrapper around useradd/usermod etc.
If you don't have the adduser utility, you can still do it with usermod:
sudo usermod -a -G staff matt
The -a flag means append (as opposed to overwrite).
I know the original question is for Linux but OSX users can do the same with this command:
sudo dseditgroup -o edit -a newusertoadd -t user grouptobeaddedto
Explanation: The operation succeeded - that's why your name appears in the right linux files on /etc/passwd & /etc/group but as soon as you open a new terminal process the bash will be updated with this setting and you can perform id matt as well.
Clarification: You added yourself to additional group so you should have used append option -a (and not editing the all bunch of groups names to your user).
sudo usermod -aG staff matt

Resources