【问题标题】:SSH through Putty comes up with a "no such file or directory"通过 Putty 的 SSH 出现“没有这样的文件或目录”
【发布时间】:2012-09-27 10:51:30
【问题描述】:

我正在尝试通过 Putty 访问 Linux 服务器,但由于某种原因,在成功登录后它只是抛出“/bin/bash 没有这样的文件或目录”然后 Putty 关闭。

bashrc 的内容:

# /etc/bashrc

# System wide functions and aliases
# Environment stuff goes in /etc/profile

# By default, we want this to get set.
# Even for non-interactive, non-login shells.
if [ $UID -gt 99 ] && [ "`id -gn`" = "`id -un`" ]; then
    umask 002
else
    umask 022
fi

# are we an interactive shell?
if [ "$PS1" ]; then
    case $TERM in
    xterm*)
        if [ -e /etc/sysconfig/bash-prompt-xterm ]; then
            PROMPT_COMMAND=/etc/sysconfig/bash-prompt-xterm
        else
            PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME%%.*}:${PWD/#$HOME/~}"; echo -ne "\007"'
        fi
        ;;
    screen)
        if [ -e /etc/sysconfig/bash-prompt-screen ]; then
            PROMPT_COMMAND=/etc/sysconfig/bash-prompt-screen
        else
        PROMPT_COMMAND='echo -ne "\033_${USER}@${HOSTNAME%%.*}:${PWD/#$HOME/~}"; echo -ne "\033\\"'
        fi
        ;;
    *)
        [ -e /etc/sysconfig/bash-prompt-default ] && PROMPT_COMMAND=/etc/sysconfig/bash-prompt-default
        ;;
    esac
    # Turn on checkwinsize
    shopt -s checkwinsize
    [ "$PS1" = "\\s-\\v\\\$ " ] && PS1="[\u@\h \W]\\$ "
fi

if ! shopt -q login_shell ; then # We're not a login shell
    # Need to redefine pathmunge, it get's undefined at the end of /etc/profile
    pathmunge () {
        if ! echo $PATH | /bin/egrep -q "(^|:)$1($|:)" ; then
            if [ "$2" = "after" ] ; then
                PATH=$PATH:$1
            else
                PATH=$1:$PATH
            fi
        fi
    }

    # Only display echos from profile.d scripts if we are no login shell
    # and interactive - otherwise just process them to set envvars
    for i in /etc/profile.d/*.sh; do
        if [ -r "$i" ]; then
            if [ "$PS1" ]; then
                . $i
            else
                . $i >/dev/null 2>&1
            fi
        fi
    done

    unset i
    unset pathmunge
fi
# vim:ts=4:sw=4

这可能是什么原因造成的?

谢谢!

【问题讨论】:

  • 非编程问题。看看这里:serverfault.com/questions/254233/…
  • 你能访问服务器位置并向我们展示 ~/.bashrc 和 ~/.bash_profile 的内容吗?
  • 我没有“bash_profile”文件。我将发布 bashrc 的内容
  • @Zaforax 我试过你给我的那个链接。我不能 chroot 到用户的主目录。同样的“/etc/bash”错误。

标签: linux ssh putty


【解决方案1】:

bash 很可能与/bin/bash 位于此 linux 机器上的不同位置

我发现在不同的盒子上都是这种情况,并且我已将我的主目录中的.profile 脚本更改为不直接执行 bash,这可能是您的解决方案。因此,当您登录时,您会留在 bourne shell,然后只有在您明确输入 bash 时才会进入 bash shell。

【讨论】:

  • 就是这样,我无法登录 :-\ 我的意思是它不会让我登录。它只是把我扔出去然后退出。
【解决方案2】:

检查您的/etc/ssh/sshd_config 以确保您没有设置chroot 目录。如果这样做,您将需要在chroot 目录中创建一个 bin 目录,然后将必要的二进制文件复制或链接到该目录中。

或者您可以随时在配置中注释该行。

无论哪种方式,重新启动 sshd 并测试。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-03-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-03-25
    • 1970-01-01
    相关资源
    最近更新 更多