One option you have is to tell sshd
to set the environment variables for you. In /etc/sshd_config
:
PermitUserEnvironment yes
In ~/.ssh/environment
:
MACHINE=1
Question
I have a target AIX 6.1 server where I need to execute a script.
The ~/.bashrc
on my target server is configured to add a variable MACHINE=1
When I ssh the server and connect I effectively view the ~/.bashrc
variables in my env:
[user@source ~]$ ssh user@10.10.10.10
[user@target]
$env |grep "MACHINE"
MACHINE=1
[user@target]
$
But when I execute directly the env
command in the ssh the variable is not set:
[user@source ~]$ ssh user@10.10.10.10 "env" |grep MACHINE
[user@source ~]$
Is there something to configure more on the server?
Solution
One option you have is to tell sshd
to set the environment variables for you. In /etc/sshd_config
:
PermitUserEnvironment yes
In ~/.ssh/environment
:
MACHINE=1
OTHER TIPS
ssh
remote command execution happens in a non-interactive shell. As such, your ${HOME}/.bashrc
, /etc/bashrc
aren't read.
If you want ssh
commands to read environment variables, add those to /etc/profile
.
Alternatively, try hacks:
ssh user@10.10.10.10 'source ${HOME}/.bashrc; echo ${MACHINE}'