【问题标题】:How to tell the difference between scp and ssh in .bash_profile如何区分 .bash_profile 中的 scp 和 ssh
【发布时间】:2016-12-03 21:38:09
【问题描述】:

我在.bash_profile 中为远程服务器嵌入了以下行:

export JMXPASS=`sudo /bin/cat /opt/jmxr.pass`

当我通过 ssh 连接到远程服务器时,系统会提示我输入密码(预期行为)。但是,当我从或向这个远程服务器进行 scp 时,我收到以下错误

sudo: no tty present and no askpass program specified

我想在 .bash_profile 中插入一个 if 条件,效果如下:

if [ssh'ing] then 
    export JMXPASS=`sudo /bin/cat /opt/jmxr.pass`
fi;

谁能告诉我需要什么条件检查?

【问题讨论】:

    标签: ssh sudo scp


    【解决方案1】:

    ~/.bashrc开头常用的条件是

    # If not running interactively, don't do anything
    case $- in
        *i*) ;;
          *) return;;
    esac
    

    如果 bash 不是交互式的(scp 情况下),它将return 并在其他情况下进一步运行。

    【讨论】:

    • 谢谢@Jakuje。根据您的建议,我查看了 /etc/.bashrc 和 /etc/.bash_profile 并找到了if shopt -q login_shell ; then # We're in a login shell。我不知道如果条件在做什么,但它对我有用。再次感谢。
    猜你喜欢
    • 2020-08-07
    • 2013-09-12
    • 1970-01-01
    • 2017-01-07
    • 1970-01-01
    • 2014-07-29
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多