如何设置$ PATH以便`ssh user @ host command`起作用? [英] How do I set $PATH such that `ssh user@host command` works?

查看:71
本文介绍了如何设置$ PATH以便`ssh user @ host command`起作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我似乎无法设置新的$ PATH,以便在通过ssh user@host command执行命令时使用它.我尝试将export PATH=$PATH:$HOME/new_path添加到远程计算机上的〜/.bashrc和〜/.profile中,但是执行ssh user@host "echo \$PATH"则表明更改尚未被使用(它显示/usr/local/sbin:/usr/local /bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games).远程计算机正在运行Ubuntu 8.04.

I can't seem to set a new $PATH such that it is used when executing commands via ssh user@host command. I have tried adding export PATH=$PATH:$HOME/new_path to ~/.bashrc and ~/.profile on the remote machine, but executing ssh user@host "echo \$PATH" shows that the change has not been picked up (it shows /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games). The remote machine is running Ubuntu 8.04.

我确定我可以将其入侵/etc/profile,但这不是一个干净的解决方案,它仅在具有root访问权限的情况下才有效.

I'm sure I could hack it into /etc/profile, but that's not a clean solution and it only works when one has root access.

推荐答案

顾名思义,〜/.bashrc是您想要的,因为它是由非交互式非登录外壳提供的.

As grawity said, ~/.bashrc is what you want, since it is sourced by non-interactive non-login shells.

我希望您遇到的问题与默认的Ubuntu〜/.bashrc文件有关.通常以以下内容开头:

I expect the problem you're having has to do with the default Ubuntu ~/.bashrc file. It usually starts with something like this:

# If not running interactively, don't do anything
[ -z "$PS1" ] && return

您要在此行之前 放置非交互式外壳的任何内容.

You want to put anything for non-interactive shells before this line.

这篇关于如何设置$ PATH以便`ssh user @ host command`起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆