Linux: Switch to nologin User

Objective: Switch and execute commands as a particular user with a nologin shell on Linux.

A nologin user entry might look something like this in the /etc/passwd file.

The above example is for the www-data user. Notice the /usr/sbin/nologin shell assigned to this user.

If you try to su to this user from root, you will most probably get the following error message.

To switch to the nologin user account using su as root, you can use the following syntax.

To switch from a non-root user, append sudo to the above command.

To run a script as a nologin user, use the following command syntax.

If you are want to use sudo and want to open a bash shell for that nologin user, use the following command syntax.

To run a script using sudo, use the following command syntax.

ibrahim = { interested_in(unix, linux, android, open_source, reverse_engineering); coding(c, shell, php, python, java, javascript, nodejs, react); plays_on(xbox, ps4); linux_desktop_user(true); }