0

I am using debian 10 and I want to create a user with no home directory. the user should only have access to the directories that his or her group owns. that is the user has only to his or her group directories. This is my command information:

useradd -g mygroup-G mygroup1,mygroup2 -s /bin/bash -M username

However when I log into the system via putty and do ls command, I see the home folder and I can cd inside it.

I don't understand why this is possible because -M should have prevented the creation of the home folder.

2
  • 2
    Do you have mkhomedir enabled in PAM or oddjobd running that would create the user's home directory when logging in?
    – spuck
    Feb 19 at 23:25
  • There are typos in that command. After you create a new user, but before you log in as that user, has the home directory been created? If not, the command is working correctly and you need to look elsewhere for the issue
    – roaima
    Feb 20 at 9:12
0

Not sure what system you are using. I tested this on CentOS-7 and worked fine as expected

[root@localhost ~]# useradd -M bruce
[root@localhost ~]# grep bruce /etc/passwd
bruce:x:1002:1004::/home/bruce:/bin/bash
[root@localhost ~]# su - bruce
su: warning: cannot change directory to /home/bruce: No such file or directory
-bash-4.2$ pwd
/root
-bash-4.2$ exit
logout
[root@localhost ~]# passwd bruce
Changing password for user bruce.
New password:
BAD PASSWORD: The password is shorter than 8 characters
Retype new password:
passwd: all authentication tokens updated successfully.
[root@localhost ~]# ssh bruce@localhost
The authenticity of host 'localhost (::1)' can't be established.
ECDSA key fingerprint is SHA256:O9p/h/nXgzhoxJragsnRHhqv/r0er1OCvIyML5X3/+4.
ECDSA key fingerprint is MD5:58:0e:65:19:0f:d9:78:8b:2d:a1:00:11:3a:c2:0b:c9.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'localhost' (ECDSA) to the list of known hosts.
bruce@localhost's password:
Last login: Fri Feb 19 22:00:56 2021
Could not chdir to home directory /home/bruce: No such file or directory
-bash-4.2$ pwd
/
-bash-4.2$
1
  • thanks for the response I am using debian 10
    – eskoba
    Feb 19 at 22:39
0

I tested on a debian bullseye without problems. There are typos? in your command : it should be

useradd -g mygroup -G mygroup1,mygroup2 -s /bin/bash -M username

There is a space missing before '-G' and too much spaces between groups names. May be it hurt?

man useradd

said

-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. The default is for the user to belong only to the initial group.

Greetings

1
  • thanks for the response, the typo was made when writting the question, I just corrected it, but in the real command there is no space. are you using debian 10? could you try to reprocude it?
    – eskoba
    Feb 20 at 10:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.