大网数据广告活动
服务器运维问答

bashrc not loaded in /bin/bash shell

· 52CE 我爱测

When I ssh into a server (4.3.3-2-ARCH), my .bashrc is not loaded (however, I can load it manually by sourcing it). I don't have any other files in my home folder, like .profile. The shell is also correct $ echo $SHELL /bin/bash …

问题原文

原帖链接 · intrixius · CC BY-SA 3.0

When I ssh into a server (4.3.3-2-ARCH), my .bashrc is not loaded (however, I can load it manually by sourcing it).

I don't have any other files in my home folder, like .profile. The shell is also correct

$ echo $SHELL
/bin/bash

When I login using ssh -t myserver /bin/bash , my .bashrc IS loaded correctly.

In SSH verbose mode, I do see that /etc/bash.bashrc and ~/.bashrc are loaded using the last command. When using the default ssh command, none of them is being loaded...

What should I configure to have .bashrc (and /etc/bash.bashrc) loaded when using the default ssh command?

已采纳解答

原帖链接 · user9517 · CC BY-SA 3.0

the ~/.bashrc file is loaded for interactive non-login shells, that's why running /bin/bash from ssh works as you expect.

For login shells (amongst others) ~/.bash_profile is read. Typically your ~/.bash_profile contains something like

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

Which ensures that ~/.bashrc is loaded if your shell is a login shell.

If your ~/.bash_profile contains the above and ~/.bashrc is not being loaded you can debug the scripts by using set -x as usual.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2016-01-07)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。