如何设置 $PATH 以使 `ssh user@host 命令` 有效? [英] How do I set $PATH such that `ssh user@host command` works?

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

问题描述

我似乎无法设置新的 $PATH,以便在通过 ssh user@host 命令 执行命令时使用它.我曾尝试将 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/游戏).远程机器运行的是 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.

推荐答案

正如 grawity 所说,~/.bashrc 就是你想要的,因为它来自非交互式非登录 shell.

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

您想在此行之前为非交互式 shell 放置任何内容.

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

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

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