为什么不使用 sshrc 中的 $PATH 设置? [英] Why is $PATH set in sshrc not used?
问题描述
我正在尝试在 OS X 服务器上通过 ssh 设置 svn.为此,我读到我需要一个包装器来设置 umask 并且 - 在我的情况下 - 设置存储库根目录.一种快速而肮脏的方法是重命名 /usr/bin/svnserve
并在该位置放置一个包装脚本.但是 SIP 可以保护该位置不受任何更改的影响,无论如何我更喜欢更简洁的解决方案.
I am trying to setup svn over ssh on an OS X server. In order to do so, I read that I need a wrapper to set umask and - in my case - to set the repository root. A quick and dirty way to do that is to rename /usr/bin/svnserve
and place a wrapper script at that location. However SIP protects that location from any changes, and I would prefer a cleaner solution anyway.
所以我在 /usr/local/bin/svnserve
创建了一个包装脚本,并用
So I created a wrapper script at /usr/local/bin/svnserve
and created /etc/ssh/sshrc
with
PATH=/usr/local/bin:$PATH
我已经通过写入日志文件验证了在从我的客户端启动远程 ssh 命令时执行此文件.但是,修改后的 PATH 似乎没有传递到命令环境:
I have verified that this file gets executed when initiating a remote ssh command from my client by writing to a log file. However, the modified PATH does not seem to get passed to the command environment:
ssh hostname 'echo $PATH'
Password:
/usr/bin:/bin:/usr/sbin:/sbin
我是否忽略了什么?或者 /etc/ssh/sshrc
是设置路径的错误位置?如果是这样,正确的地方是什么?
Am I overlooking something? Or is /etc/ssh/sshrc
the wrong place to set a path? If so, what's the right place?
我尝试过的其他地方:/etc/profile
和 /etc/bashrc
,但这些似乎都没有与 ssh 命令一起执行.
Other places I've tried: /etc/profile
and /etc/bashrc
, but none of these seem to get executed in connection with an ssh command.
注意:这不是更改客户端行为的选项(例如,向命令添加所需的路径).
推荐答案
/etc/sshrc
与远程发出的命令不在同一个 shell 实例中运行,因此 PATH 更新不会持续通过.
/etc/sshrc
does not run in the same shell instance with the remotely-issued command, so the PATH update does not persist through.
一些可用的选项:
- 您可以在服务器端设置
AcceptEnv PATH
,将其配置为接受远程系统发送的PATH,在客户端设置SendEnv PATH
(在~/.ssh/config
,或作为 ssh 的参数通过-o
传递,或在/etc/ssh/ssh_config
中). - 在服务器上的
/etc/ssh/sshd_config
中,您可以将选项PermitUserEnvironment
设置为yes
;完成后,可以将变量和值添加到服务器上个人用户帐户中的~/.ssh/environment
. - 您可以使用
ForceCommand
覆盖远程请求的命令,或者使用类似/usr/bin/env PATH=/usr/local/bin:/usr/bin:/binsvnserve
或简单的/usr/local/bin/svnserve
- You can set
AcceptEnv PATH
on the server to configure it to accept a PATH sent by the remote system, andSendEnv PATH
on the client (in~/.ssh/config
, or as an argument to ssh passed with-o
, or in/etc/ssh/ssh_config
). - In
/etc/ssh/sshd_config
on the server, you can set the optionPermitUserEnvironment
toyes
; with that done, the variable and value can be added to~/.ssh/environment
in the individual user's account on the server. - You can use
ForceCommand
to override the remotely requested command, either with something like/usr/bin/env PATH=/usr/local/bin:/usr/bin:/bin svnserve
or simply/usr/local/bin/svnserve
这篇关于为什么不使用 sshrc 中的 $PATH 设置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!