There is a sentence in the post below.
Difference between Login Shell and Non-Login Shell?

The focus is here:
Another way to get a non-interactive login shell is to log in remotely with a command passed through standard input which is not a terminal, e.g.
ssh example.com <my-script-which-is-stored-locally (as opposed to ssh example.com my-script-which-is-on-the-remote-machine, which runs a non-interactive, non-login shell).

The author arrives at two conclusions from the description above.

  1. non-interactive login shell

     ssh example.com <my-script-which-is-stored-locally           
  2. non-interactive, non-login shell

     ssh example.com my-script-which-is-on-the-remote-machine

I don't think the second conclusion is right.
When to execute ssh example.com my-script-which-is-on-the-remote-machine, account name and password still be asked to input locally.
It is still a non-interactive login shell!

login shell: A login shell logs you into the system as a specified user, necessary for this is a username and password
According to the web description on login shell

For the non-interactive non-login shell, give an example here: some daemon such as mysqld or apache2, all of them are non-interactive non-login shells.

It is your turn: true or false?

  • 1
    “logs you into the system as a spiecified user” is not a good definition of a login shell. Read my answer to understand what a login shell is. Commented Mar 6, 2017 at 21:18

2 Answers 2


When to execute ssh example.com my-script-which-is-on-the-remote-machine, account name and password still be asked to input locally.

It is still a non-interactive login shell!

The interactivity of the login shell is not defined by the case "you enter login and password". You are prompted for the password by your local ssh (or the keys are used), it passes them to the remote sshd server and only if they are correctly verified, you are given a shell (unless you use UseLogin yes in the sshd_config, which is quite dangerous).


The login is the core concept in jargon--login shell.
There are four stages abstracted to describe linux work:Init, Getty, Login , Shell.
Here login is a program, which gets the username as a parameter, and prompts the user for the password.
On local side:

vim   /tmp/shell.sh   
shopt login_shell 

On server side(my vps server):

vim   /tmp/shell.sh   
shopt login_shell 

1.non-interactive login shell
general format: ssh example.com <my-script-which-is-stored-locally

ssh  root@vps_ip  < /tmp/shell.sh
Pseudo-terminal will not be allocated because stdin is not a terminal.
login_shell     on

More clearly

ssh -t -t root@vps_ip  < /tmp/shell.sh
Last login: Wed Mar  8 03:16:00 2017 from vps_ip
root@localhost:~$ shopt login_shell 
login_shell     on

The interpreter on local side break ssh -t -t root@vps_ip < /tmp/shell.sh into two parts.
1.ssh -t -t root@vps_ip
login program accept root as user on the vps,logined.
the script on the local side passed as a parameter into interpreter on remote side ,and executed.

It is non-interactive login shell during the process.

2.non-interactive non-login shell
general format:ssh example.com my-script-which-is-stored-on-remote-machine

debian8@hwy:~$ssh   root@vps_ip  '/bin/bash /tmp/shell.sh'
login_shell     off

It is non-interactive non-login shell during the process.

Some hack trick can make it display as login shell.

debian8@hwy:~$ssh   root@vps_ip  '/bin/bash --login /tmp/shell.sh'
login_shell     on

The vps server does not be logined after the whole command ssh root@vps_ip '/bin/bash --login /tmp/shell.sh' performed.
The login_shell on displayed no meaning,it logined but vps server closed connection ,logined out.
Gilles's conclusions on non-interactive login shell and non-interactive non-login shell is right.

  • I accidentally added a source statement to my /etc/bash.bashrc file that contained an exit 0 command at the end of the script sourced every time when accessing the server. ssh -t -t root@vps_ip < /tmp/shell.sh This command saved my ass, thank you.
    – Akito
    Commented Apr 8, 2019 at 12:44

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .