Ssh – Why does bash invocation differ on AIX when using telnet vs ssh

aixbashsshtelnet

I am using an AIX 5.3 server with a .bashrc file set up to echo "Executing bashrc." When I log in to the server using ssh and run:

bash -c ls

I get:

Executing bashrc
.
..
etc....

However, when I log in with telnet as the same user and run the same command I get:

.
..
etc....

Clearly in the telnet case, the .bashrc was not invoked. As near as I can tell this is the correct behaviour given that the shell is non-interactive in both cases (it is invoked with -c). However, the ssh case seems to be invoking the shell as interactive. It does not appear to be invoking the .profile, so it is not creating a login shell. I cannot see anything obviously different between the environments in the two cases.

What could be causing the difference in bash behaviour?

Best Answer

Check to make sure that the login shell you're in doesn't have an alias or a different PATH depending on whether you're logged in via ssh or telnet. Compare this each way:

type -a bash

There could be some conditional code in one of:

  • /etc/profile
  • /.bash_profile
  • ~/.bash_login
  • ~/.profile
  • ~/.bashrc

That sets the PATH differently or creates an alias depending on whether you're logged in via ssh or telnet. The PATH could point to different versions of Bash that are compiled with different options. An alias could be something like alias bash='bash -i'.

If you echo $SHELL as Nikolaidis suggests, that's only going to show what's set in /etc/passwd as your login shell. It might be more reliable to use ps. If for some reason you're getting a shell other than Bash, you'll need to check its startup files and environment to see if the PATH or aliases are different. Generally, though, your interactive shell shouldn't affect how explicitly calling bash -c works.

And you're correct about this:

As near as I can tell this is the correct behaviour given that the shell is non-interactive in both cases (it is invoked with -c).