At the end of .bashrc
I added:
touch /tmp/bash_noninteractive_test
Run:
/usr/bin/ssh -v -C root@example.com 'ls'
On the host (logged in interactively before):
% ls -l /tmp/bash_noninteractive_test
ls: cannot access /tmp/bash_noninteractive_test: No such file or directory
I thought ~./bashrc
is ALWAYS sourced in non-interactive shells, like over SSH? How do I fix that?
Systems affected:
% lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 14.04.5 LTS
Release: 14.04
Codename: trusty
% lsb_release -a
No LSB modules are available.
Distributor ID: Debian
Description: Debian GNU/Linux 8.11 (jessie)
Release: 8.11
Codename: jessie
Best Answer
From the INVOCATION chapter of
man bash
:So it appears that
~/.bashrc
is never sourced on non-interactive shells, unlessBASH_ENV
points to it.Depending on what you wish to actually achieve, you might consider enabling
PermitUserRC
and/orPermitUserEnvironment
in/etc/ssh/sshd_config
on your remote host, and then writing the desired environment variables in~/.ssh/environment
and/or the desired commands in~/.ssh/rc
.NOTE: if you plan to use SSH X11 forwarding together with
~/.ssh/rc
, you must include a snippet of code to explicitly feed the X11 session to thexauth -q -
command; see the example in the SSHRC chapter ofsshd(8)
man page.