Ubuntu – When I ssh into a ubuntu machine, what kind of shell am I using

bashshellsshUbuntu

I keep reading about interactive, non-interactive, login, and non-login shells.

(This is in the context of which of the .bash* files is read).

I don't understand what each type of shell is, so let's start with the basics.

If I ssh from my mac to my ubuntu machine, what type of shell is getting fired up?

Best Answer

If you SSH into your Ubuntu box, you're getting an interactive login shell. Here's the difference:

  • Interactive vs. non-interactive: Any shell where you can type at a prompt is interactive. In fact, many scripts test for the variable $PS1 which holds the prompt string to find out whether they're interactive. If a shell is executing a shell script, it's non-interactive.

    So, if you do ssh yourbox.example.com, you'll get an interactive shell, asuming default settings, while if you do ssh yourbox.example.com mighty_shellscript.sh, you'll end up with a non-interactive shell and your SSH session will terminate when the script terminates.

  • Login vs. non-login: When you log in from the console or remotely (such as SSH), or when you pass the -l option to bash, you get a login shell. Otherwise--such as when you open up a terminal window--you get a non-login shell.

    To test whether a shell is a login shell, check whether its command name is -bash instead of bash:

    ps -ef | grep [b]ash