Linux – Centos User account nologin but possible to su into account

centoslinux

I'm new to CentOS (running CentOS 6). I have previous experience with OpenSuse.

I'm trying to setup an account for a user. I don't want the account to be available for login via ssh or via the login screen. But, I still want to be able to log into the user by using su command. This allows me to run certain applications as the user with restricted access. The user is not a super user, so it cannot effect applications of other users.

Any help would be greatly appreciated. I generally want to use this to run Glassfish server etc.

Best Answer

On centos, you would setup with a user with no shell by using /sbin/nologin:

[root@localhost ~]# grep named /etc/passwd
named:x:25:25:Named:/var/named:/sbin/nologin
[root@localhost ~]# 

If you need to become that, use -s parameter and put as the argument the shell of your choice, like so:

[root@localhost ~]# su - named -s /bin/bash
-bash-4.1$ 

Note that if you use bash, it will read the settings from /etc/profile first and will default to those settings if there is no existing .bash_profile, .bash_login or.profile in the user home directory. Of course, if you want to use your existing environment settings that exists in root, you can just remove the dash:

exit [

root@localhost ~]# su - named -s /bin/bash
-bash-4.1$ echo $PATH
/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin
-bash-4.1$ exit
logout
[root@localhost ~]# su named -s /bin/bash
bash-4.1$ echo $PATH
/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin
bash-4.1$ 
Related Topic