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

5

1

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?

Tyler DeWitt

Posted 2012-09-26T00:03:13.827

Reputation: 223

Answers

3

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
    

Scott Severance

Posted 2012-09-26T00:03:13.827

Reputation: 531

Thanks for the writeup. Been confused on that since the beginning of time – Tyler DeWitt – 2012-09-26T14:33:51.757

2

You get an interactive login shell. But don't take it for granted, check it yourself.

This tells you that you have a login shell (from man bash):

# shopt | grep login
login_shell     on

This tells you that you have an interactive shell, look for the i (from man bash):

# echo $-
himBH

The interactive login shell you get has read /etc/profile and than one of ~/.bash_profile, ~/.bash_login and ~/.profile, as explained in man bash:

When bash is invoked as an interactive login shell, or as a non-interactive shell with the --login option, it first reads and executes commands from the file /etc/profile, if that file exists. After reading that file, it looks for ~/.bash_profile, ~/.bash_login, and ~/.profile, in that order, and reads and executes com‐ mands from the first one that exists and is readable. The --noprofile option may be used when the shell is started to inhibit this behavior.

jaume

Posted 2012-09-26T00:03:13.827

Reputation: 4 947

0

Try this command.

[max@localhost ~]$ echo $SHELL
/bin/bash

you are getting this output because your shell type is stored in this variable SHELL.

To know your environment variable type this command

[max@localhost ~]$ env
.
.
.
HOSTNAME=localhost.localdomain
SHELL=/bin/bash
HISTSIZE=1000
USER=max
.
.
.

while typing echo $SHELL it will print the value whatever stored here

This value gets updated for every bootup

max

Posted 2012-09-26T00:03:13.827

Reputation: 3 329

This answer is incorrect. Booting has no effect whatsoever on the value of $SHELL. Plus, this answer doesn't answer the OP's question about what type of shell fires up (interactive login in the OP's example). – Scott Severance – 2012-09-26T07:58:26.673

@ScottSeverance ok answer may be wrong but what is This "Booting has no effect whatsoever on the value of $SHELL" .... Now change your shell to tcsh after changing shell reboot system and now type $SHELL. it will give /bin/tcsh... see here [max@localhost ~]$ echo $SHELL /bin/tcsh... – max – 2012-09-26T09:16:24.667

So, if you use chsh to change the default shell, of course the change will be visible after rebooting, just like if I save a file, the change will be visible after rebooting. But rebooting isn't what applies the change. Any login shell will notice the change. That means you can log out and back in, or reboot, or run gnome-terminal -x bash -l, or use one of many other methods. – Scott Severance – 2012-09-26T23:09:32.587

0

The ssh(1) man page says,

If command is specified, it is executed on the remote host instead of a login shell.

and

When the user's identity has been accepted by the server, the server either executes the given command, or logs into the machine and gives the user a normal shell on the remote machine.

Those suggest to me that the shell you're getting is a login shell.

garyjohn

Posted 2012-09-26T00:03:13.827

Reputation: 29 085