I am trying to use plink as an ssh alternative on windows, but I am finding that when plink connects to a remote linux machine, it does not source .bash_profile or .bashrc.
Is there a different dot file I should create? Or is there another option?
For example, my bashrc file adds a directory to my path. This directory contains extra programs that I want to use, one being python.
This will not work:
plink host python
Where as this will:
plink host "source .bashrc;python"
When I use plink without a command parameter, it sources .bash_profile and everything works fine, but it appear that by merely sending a command plink will not source either file.
Is there a workaround?
bash_profile contains lines like below that source the . bashrc file. This means each time you log in to the terminal, both files are read and executed.
More typically Plink is used with the SSH protocol, to enable you to talk directly to a program running on the server. To do this you have to ensure Plink is using the SSH protocol. You can do this in several ways: Use the -ssh option as described in section 7.2.
Log in under this account and bring up a command shell. For each host you need to connect to, invoke plink -ssh <user>@<host name> , and when prompted about the key fingerprint, answer y to cache the value. No other commands are needed; you can exit any interactive shells that are invoked.
Windows/MS-DOS notes The folders c:\windows\ or c:\winnt\ are typically in the path, so these are good places to copy the file plink.exe to.
The accepted answer helped me solve the same problem using plink. Here is a bit more detail that may help people in future:
When a ssh connection is made to run a single command using plink, bash is not invoked as an "interactive login shell", so it doesn't run /etc/profile, ~/.bash_profile, ~/.bash_login, or ~/.profile (see the bash manual pages).
For my purposes, I needed ~/.profile to run prior to the command passed in the plink command line.
A forced command can be added to the authorized_keys file for that key (see the sshd manual pages). A forced command (e.g. to run ~/.profile) stops it running the command specified by plink, so to get it to do both, the forced command should be to execute a script that runs .profile then the original plink command. The latter is stored in an environment variable $SSH_ORIGINAL_COMMAND so your script can do
source .profile
$SSH_ORIGINAL_COMMAND
and you specify the script in the ~/.ssh/authorized_keys file as follows, before the key, on the same line:
command="source forced_command.script" ssh-rsa A3AABzaC1yc...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With