O OpenSSH (provavelmente o que você está executando) decide se deve ou não criar um shell de login, e isso só acontece se você não estiver executando um comando específico. De man ssh
:
If command is specified, it is executed on the remote host instead of a login shell.
Portanto, é uma escolha de implementação para o servidor ssh se ele deseja criar um shell de login ou não, e se você der um comando para executar, ele não o fará.
Enquanto ssh
realiza um login, se você está tendo que executar um comando e sair, é muito mais semelhante a criar um shell apenas para executar esse comando do que para obter um ambiente de login. Parece que, dado que as pessoas que escrevem o OpenSSH decidiram tratá-lo como esse tipo de tarefa.
Eles criam um shell não-interativo, sem logon, para executar o comando, porque esse é o espírito de executar um comando em outro contexto / shell. Normalmente, no entanto, os shells não interativos não criam automaticamente ~/.bashrc
, o que está claramente acontecendo aqui. O bash
está realmente tentando nos ajudar aqui. De os documentos
Invoked by remote shell daemon
Bash attempts to determine when it is being run with its standard input connected to a network connection, as when executed by the remote shell daemon, usually rshd, or the secure shell daemon sshd. If Bash determines it is being run in this fashion, it reads and executes commands from ~/.bashrc, if that file exists and is readable. It will not do this if invoked as sh. The --norc option may be used to inhibit this behavior, and the --rcfile option may be used to force another file to be read, but neither rshd nor sshd generally invoke the shell with those options or allow them to be specified.