简体   繁体   English

Plink不会在连接时提供bashrc或bash_profile

[英]Plink does not source bashrc or bash_profile on connect

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. 我试图在Windows上使用plink作为ssh替代品,但我发现当plink连接到远程linux机器时,它不会提供.bash_profile或.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. 例如,我的bashrc文件在我的路径中添加了一个目录。 This directory contains extra programs that I want to use, one being python. 这个目录包含我想要使用的额外程序,一个是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. 当我在没有命令参数的情况下使用plink时,它会输出.bash_profile并且一切正常,但看起来仅通过发送命令plink将不会获取任何文件。

Is there a workaround? 有解决方法吗?

The accepted answer helped me solve the same problem using plink. 接受的答案帮助我使用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). 当使用plink运行单个命令的ssh连接时,不会将bash作为“交互式登录shell”调用,因此它不会运行/ etc / profile,〜/ .bash_profile,〜/ .bash_login或〜/ .profile(参见bash手册页)。

For my purposes, I needed ~/.profile to run prior to the command passed in the plink command line. 为了我的目的,我需要〜/ .profile在plink命令行中传递的命令之前运行。

A forced command can be added to the authorized_keys file for that key (see the sshd manual pages). 可以将强制命令添加到该密钥的authorized_keys文件中(请参阅sshd手册页)。 A forced command (eg 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. 强制命令(例如运行〜/ .profile)会阻止它运行plink指定的命令,因此要使它同时执行这两项操作,强制命令应该是执行运行.profile然后执行原始plink命令的脚本。 The latter is stored in an environment variable $SSH_ORIGINAL_COMMAND so your script can do 后者存储在环境变量$ SSH_ORIGINAL_COMMAND中,因此您的脚本可以执行此操作

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: 然后在同一行的键之前的〜/ .ssh / authorized_keys文件中指定脚本,如下所示:

command="source forced_command.script" ssh-rsa A3AABzaC1yc...

If you simply connect to a remote host via ssh or plink, it will start the login account's default shell. 如果您只是通过ssh或plink连接到远程主机,它将启动登录帐户的默认shell。 If that shell is bash, bash will automatically source .bash_profile. 如果该shell是bash,bash将自动获取.bash_profile。

If you connect to a remote host via ssh or plink asking for a command to be executed, ssh will try to execute just that command. 如果通过ssh或plink连接到远程主机,要求执行命令,ssh将尝试执行该命令。

What you want to achieve can be done by using a ForcedCommand . 您想要实现的目标可以通过使用ForcedCommand来完成。 See also here: 另见:

Set the forced command to be a script that does 2 things: 将强制命令设置为执行以下两项操作的脚本:

  1. source the .bash_profile 找到.bash_profile
  2. run original command (env vars $SSH_ORIGINAL_COMMAND or $SSH2_ORIGINAL_COMMAND) 运行原始命令(env vars $ SSH_ORIGINAL_COMMAND或$ SSH2_ORIGINAL_COMMAND)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使Windows Git Bash终端查找.bashrc和.bash_profile的自定义位置 - Make Windows Git Bash terminal look to a custom location for .bashrc & .bash_profile 运行“ Cygwin.bat”和仅运行“ bash”时的区别(.bash_profile与.bashrc) - Difference when running 'Cygwin.bat' and if just running 'bash' (.bash_profile vs. .bashrc) 还有哪些其他可能的来源 Git Bash 可能来自 ~/.bashrc 和 ~/.bash_profile - What are some other possible sources Git Bash could be pulling from other than ~/.bashrc and ~/.bash_profile 在Windows 10上运行VSCode任务时无法加载.bash_profile或.bashrc - Unable to load .bash_profile or .bashrc when running VSCode tasks on windows 10 Windows 10 中“Bash on Ubuntu on Windows”的 .bashrc 位置 - Location of .bashrc for "Bash on Ubuntu on Windows" in Windows 10 git-bash 生成 default.bashrc - git-bash generate default .bashrc 适用于 Windows 的 Git:.bashrc 或 Git Bash shell 的等效配置文件 - Git for Windows: .bashrc or equivalent configuration files for Git Bash shell gitbash(缓存密码短语密钥):无法使ssh-agent在Windows上运行,已修改.bashrc和.profile - gitbash (cache passphrase key): Can't get the ssh-agent to run on windows, modified the .bashrc & .profile Plink工作目录 - Plink working directory plink自动批处理脚本 - plink automated batch script
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM