Home > Blockchain >  Does ssh command intercept a remote host before it executes .bashrc?
Does ssh command intercept a remote host before it executes .bashrc?

Time:01-18

If there is a host, which modifies .bashrc, so that it immediately logout users who login with SSH.

If I login to the remote host by entering a command like:

ssh user@hostname bash

then, does the bash, which is next to the user@hostname, executed before the .bashrc file or even ignore it?

I tried with that command, and was possible to access to the host. It was quite different with a normal terminal because there was nothing other than a blinking cursor, but was able to run serveral linux commands, and even it was possible to see a contents inside txt files via cat command.

But, when I entered like:

ssh -t user@hostname bash

the connection automatically closed down.

I can’t explain, precisely, what is happening under the hood and the mechanism of -t option with bash.

CodePudding user response:

What is an interactive shell?

An interactive shell is one started without non-option arguments (unless -s is specified) and without specifying the -c option, whose input and error output are both connected to terminals (as determined by isatty(3)), or one started with the -i option.

Startup Files:

When an interactive shell that is not a login shell is started, Bash reads and executes commands from ~/.bashrc, if that file exists. This may be inhibited by using the --norc option. The --rcfile file option will force Bash to read and execute commands from file instead of ~/.bashrc.

In short, allocating a pseudo-tty with the -t option satisfies the requirement that input and error output are both connected to terminals (as determiend by isatty(3)) to cause bash to be invoked in interactive mode. Interactive shells read the .bashrc file which contains your undesired line.

You can make the bash shell read something else with --rcfile or ignore the file entire with --norc, although there isn't a guarantee that another startup file won't independently read bashrc itself.

  • Related