除非运行“bash”命令,否则 SU 或 SSH 登录后 BASH 和/或 .BASHRC 无法正常工作

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8607473/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 01:12:39  来源:igfitidea点击:

BASH and/or .BASHRC not working properly after SU or SSH login unless run "bash" command

linuxbashubuntuamazon-ec2

提问by Mikey

I have an Amazon EC2 Machine running Ubuntu 10.04.

我有一台运行 Ubuntu 10.04 的 Amazon EC2 机器。

The default user, ubuntu's .bashrcseems to be behaving properly, but if I sshor suto the second user, mikey, it doesn't display properly until I run bash:

默认用户 ubuntu.bashrc似乎行为正常,但是如果我sshsu第二个用户 mikey,它在我运行之前不会正确显示bash

Ex 1.) Changing user with su

例 1.) 更改用户 su

mikey@home ~$ ssh ubuntu@EC2
ubuntu@EC2:~$
ubuntu@EC2:~$ su mikey
$ 
$ bash
mikey@EC2: $

Ex 2.) SSH-ing in directly as the user

Ex 2.) 直接以用户身份登录

mikey@home ~$ ssh mikey@EC2
/home/mikey/.bashrc: 13: shopt: not found
/home/mikey/.bashrc: 21: shopt: not found
/home/mikey/.bashrc: 99: shopt: not found
/etc/bash_completion: 33: [[: not found
/etc/bash_completion: 39: [[: not found
/etc/bash_completion: 52: Bad substitution
\[\e]0;\u@\h: \w\a\]\u@\h:\w$
\[\e]0;\u@\h: \w\a\]\u@\h:\w$ bash
mikey@EC2:~$

I've tried playing around with ~/.profileand ~/.bash_loginto include

我试过玩弄~/.profile~/.bash_login包括

if [ -f ~/.bashrc ]; then
        . ~/.bashrc
fi

but so far, nothing has seemed to do the trick.

但到目前为止,似乎没有什么可以解决问题。

any pointers would be greatly appreciated. thanks!

任何指针将不胜感激。谢谢!

回答by Dan Fego

If, in fact, your shell isn't bash, you can try to change it like so:

如果实际上您的 shell 不是bash,您可以尝试像这样更改它:

usermod -s /bin/bash mikey

If /bin/bash is the location of bashon that system.

如果 /bin/bash 是该bash系统上的位置。

回答by favoretti

I think your default shell is dashor shand not bashin this case. echo $SHELLshould show it, should it show /bin/sh, it might be a link, so check that ls -l /bin/shdoesn't link to some other shell.

在这种情况下,我认为您的默认 shell 是dashsh不是bashecho $SHELL应该显示它,如果它显示/bin/sh,它可能是一个链接,所以检查ls -l /bin/sh它没有链接到其他一些 shell。

回答by michael

In order to fix this on the permanent basis, change /etc/passwd

为了永久修复此问题,请更改 /etc/passwd

From:

从:

kwilson:x:3042:3042::/home/jjson:/bin/sh

kwilson:x:3042:3042::/home/jjson:/bin/sh

Change it to:

将其更改为:

kwilson:x:3042:3042::/home/jjson:/bin/bash

kwilson:x:3042:3042::/home/jjson:/bin/bash

回答by Felipe Alvarez

Can't you use chshto change shell? instead of hacking /etc/passwd?

chsh换壳不能用吗?而不是黑客 /etc/passwd?