In this article I will show you how to create a user with no home (login) directory, in Debian, Ubuntu and other debian based Linux distros.
Doing this with the useradd command is simple, if you don’t want a user with a homedir, do not specify it in the useradd command:
# useradd -s /bin/bash test_user
# su - test_user
No directory, logging in with HOME=/
!Note: useradd -r does not create only a user with no homedir, it creates a system user (with UID in the system user range or with no aging information in /etc/shadow…)
But this also can be done with the adduser interactive command: adduser –no-create-home username
$ adduser --no-create-home test_user2
Adding user `test_user2' ...
Adding new group `test_user2' (1024) ...
Adding new user `test_user2' (1009) with group `test_user2' ...
Not creating home directory `/home/test_user2'.
[...]
Test:
# grep test_user* /etc/passwd
test_user:x:1020:1051::/home/test_user:/bin/bash
test_user2:x:1009:1024:,,,:/home/test_user2:/bin/bash
# su - test_user
No directory, logging in with HOME=/
$ exit
# - test_user2
No directory, logging in with HOME=/
$ exit
The username is set in the /etc/passwd file, but it does not exist in reality. It’s like creating a normal user and deleting it’s homedir from the hard drive.
Leave a Reply