ssh example.com somecommand
doesn't read your ~/.profile
; somecommand
is executed directly by the ssh daemon. When you don't specify a command, the ssh daemon invokes your login shell, which reads your ~/.profile
. (Substitute ~/.bash_profile
, ~/.zprofile
or ~/.login
depending on your login shell.)
There are a few ways to set environment variables for a non-interactive command, but they all require a setting in the server configuration which is typically off by default. Assuming a recent enough OpenSSH on both sides:
You can have environment variables sent from the client to the server with the SendEnv
directive in ~/.ssh/config
. The specific environment variable must be enabled with an AcceptEnv
directive in the server configuration.
You can set environment variables through ~/.ssh/environment
on the server side. This must be enabled in the server configuration with the PermitUserEnvironment
directive.
Assuming you use key-based authentication, you can also set per-origin variables in ~/.ssh/authorized_keys
: add environment="FOO=bar"
at the beginning of the relevant line. Again, you need the PermitUserEnvironment
directive in the server configuration.
If you can't or don't want to change the server configuration, you'll have to write the full path to the remote command, or explicitly source your .profile
in the remote command.
ssh user@10.0.0.5 -Y '. ~/.profile; netbeans'
ssh user@10.0.0.5 -Y '/path/to/netbeans'