SSH without sourcing .bashrc
As discussed in the other answer, when an SSH client connects to the OpenSSH server, the OpenSSH server will generally start a shell session on the client's behalf, using the user's login shell:
- If the client requests an interactive session, the server will launch the user's login shell.
- If the client requests running a command, the server will use the user's login shell to run the command as a shell command.
- Utilities like
scp
,rsync
, andgit
which use ssh for transport will request a command to be run on the remote system, so they fall under #2.
If you have something in the remote user's shell startup files which causes the shell to exit, then you will have trouble getting in.
SFTP however is a special case. The OpenSSH server may be configured to support SFTP without launching an external command. If that's the case, then you'd be able to use sftp to connect to the server and delete, rename, or alter the .bashrc
file which is causing the problem.
It depends on how the server is configured to support sftp. It can service sftp sessions by launching an external program (named sftp-server
). In this case you'd have the same problem getting in that you have with programs like scp
. Or, the server can service sftp session by something referred to "internal-sftp", which doesn't require invoking a shell. It just depends on how the particular SSH server is configured.