4

I'm just learning linux. Working as root, I created a new user called testuser. I then changed testuser to a nologin shell.

Now I want to login as the testuser to see what a user with a nologin shell can/can't do.

I tried: su testuser and got: This account is currently not available. I tried: su - testuser and got: su: warning: cannot change directory to /home/testuser: No such file or directory This account is currently not available.

How do I switch from root to a user with a nologin shell?

1
8

The point of the nologin shell is to prevent the user from logging in. Such a user may still use your server services like FTP, IMAP/POP3 and others but they won't be able to login e.g. using sshd or console, period.

How do I switch from root to a user with a nologin shell?

sudo -u USERNAME /bin/bash

Will work but only root can do that.

0
2

Artem's answer is good, but if sudo isn't available, it is also possible to use

su --shell /bin/bash USERNAME

From the su manual about the -s/--shell flag:

If the target user has a restricted shell (i.e. the shell field of this user's entry in /etc/passwd is not listed in /etc/shells), then the --shell option or the $SHELL environment variable won't be taken into account, unless su is called by root.

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.