Re: ssh does not source /etc/bash.bashrc, but manual execution of /bin/bash does it under specific circumstances
Hello Chet and Eduardo, thank you very much for your replies. Everything is crystal clear now. Sorry for the 'wrong alarm' (: Best, Nick On 20/12/2016 20:24, Chet Ramey wrote: On 12/20/16 11:11 AM, Nick wrote: i came up with a weird behavior of ssh+bash on my Debian box (8.6). I created an alias in /etc/bash.bashrc file, which is sourced through /etc/profile. Everything worked fine, till i decided to remove the '. /etc/bash.bashrc' line from /etc/profile. When i` m connected via ssh the '/etc/bash.bashrc' is not sourced and the alias does not work as expected. But, when i execute bash from my shell, the '/etc/bash.bashrc' seems to be sourced and the alias is there (please find bellow a demo) ssh without a command is equivalent to slogin, which starts a login shell on the remote host. Login shells don't execute ~/.bashrc (and, if so configured, SYS_BASHRC), so there's usually a line to source it in one of the login shell startup files (/etc/profile in your case). That's why it's there, and that's why removing it had the effect you observed. Not sure if i miss something (f.x. bash is executed with different flags while being called from ssh versus a user), but as far as i understand, the same things should be (or not) sourced. Well, it's the difference between a login shell and a non-login interactive shell.
Re: ssh does not source /etc/bash.bashrc, but manual execution of /bin/bash does it under specific circumstances
On 12/20/16 11:11 AM, Nick wrote: > i came up with a weird behavior of ssh+bash on my Debian box (8.6). > I created an alias in /etc/bash.bashrc file, which is sourced through > /etc/profile. > Everything worked fine, till i decided to remove the '. > /etc/bash.bashrc' line from /etc/profile. > When i` m connected via ssh the '/etc/bash.bashrc' is not sourced and > the alias does not work as expected. > But, when i execute bash from my shell, the '/etc/bash.bashrc' seems > to be sourced and the alias is there (please find bellow a demo) ssh without a command is equivalent to slogin, which starts a login shell on the remote host. Login shells don't execute ~/.bashrc (and, if so configured, SYS_BASHRC), so there's usually a line to source it in one of the login shell startup files (/etc/profile in your case). That's why it's there, and that's why removing it had the effect you observed. > Not sure if i miss something (f.x. bash is executed with different > flags while being called from ssh versus a user), but as far as i understand, > the same things should be (or not) sourced. Well, it's the difference between a login shell and a non-login interactive shell. -- ``The lyf so short, the craft so long to lerne.'' - Chaucer ``Ars longa, vita brevis'' - Hippocrates Chet Ramey, UTech, CWRUc...@case.eduhttp://cnswww.cns.cwru.edu/~chet/
Re: ssh does not source /etc/bash.bashrc, but manual execution of /bin/bash does it under specific circumstances
Please read http://mywiki.wooledge.org/DotFiles#Remote_shell_logins (perhaps read http://mywiki.wooledge.org/DotFiles#Console_logins first). The key to understanding this is to know that there are three basic types of shell startup: - Login shell - Interactive shell - Non-login Non-interactive shell (scripts and -c) Each of these startup modes source different files. You need to make sure you layout your initialization files with that in mind.
ssh does not source /etc/bash.bashrc, but manual execution of /bin/bash does it under specific circumstances
Configuration Information [Automatically generated, do not change]: Machine: x86_64 OS: linux-gnu Compiler: gcc Compilation CFLAGS: -DPROGRAM='bash' -DCONF_HOSTTYPE='x86_64' -DCONF_OSTYPE='linux-gnu' -DCONF_MACHTYPE='x86_64-pc-linux-gnu' -DCONF_VENDOR='pc' -DLOCALEDIR='$ uname output: Linux katastrofi 3.16.0-4-amd64 #1 SMP Debian 3.16.36-1+deb8u2 (2016-10-19) x86_64 GNU/Linux Machine Type: x86_64-pc-linux-gnu Bash Version: 4.3 Patch Level: 30 Release Status: release Description: Hello, i came up with a weird behavior of ssh+bash on my Debian box (8.6). I created an alias in /etc/bash.bashrc file, which is sourced through /etc/profile. Everything worked fine, till i decided to remove the '. /etc/bash.bashrc' line from /etc/profile. When i` m connected via ssh the '/etc/bash.bashrc' is not sourced and the alias does not work as expected. But, when i execute bash from my shell, the '/etc/bash.bashrc' seems to be sourced and the alias is there (please find bellow a demo) Not sure if i miss something (f.x. bash is executed with different flags while being called from ssh versus a user), but as far as i understand, the same things should be (or not) sourced. Best, Nick Please find /etc/bash.bashrc, /etc/profile and my home directory under this link: www.katastrofi.eu/nick.tar.gz # Demo root@RBMK-1000:~# ssh nick@10.250.251.12 ssh nick@10.250.251.12 nick@10.250.251.12's password: The programs included with the Debian GNU/Linux system are free software; the exact distribution terms for each program are described in the individual files in /usr/share/doc/*/copyright. Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent permitted by applicable law. Last login: Tue Dec 20 17:29:37 2016 from 10.250.251.238 bla nick@RBMK-1000:~$ ll -bash: ll: command not found nick@RBMK-1000:~$ bash nick@RBMK-1000:~$ ll total 24 drwxr-xr-x 2 nick nick 4096 Dec 20 17:28 . drwxr-xr-x 3 root root 4096 Dec 13 22:06 .. -rw--- 1 nick nick 195 Dec 20 17:29 .bash_history -rw-r--r-- 1 nick nick 220 Nov 4 12:58 .bash_logout -rw-r--r-- 1 nick nick 3515 Nov 4 12:58 .bashrc -rw-r--r-- 1 nick nick 675 Nov 4 12:58 .profile nick@RBMK-1000:~$ # nick login shell nick@katastrofi:~$ grep nick /etc/passwd nick:x:1000:1000:,,,:/home/nick:/bin/bash nick@katastrofi:~$ # OS nick@RBMK-1000:~$ uname -a Linux RBMK-1000 3.16.0-4-amd64 #1 SMP Debian 3.16.36-1+deb8u2 (2016-10-19) x86_64 GNU/Linux nick@RBMK-1000:~$ lsb_release -a No LSB modules are available. Distributor ID: Debian Description:Debian GNU/Linux 8.6 (jessie) Release:8.6 Codename: jessie nick@RBMK-1000:~$ # Packages installed nick@RBMK-1000:~$ dpkg -l | grep bash ii bash 4.3-11+b1 amd64 GNU Bourne Again SHell ii bash-completion1:2.1-4 all programmable completion for the bash shell nick@RBMK-1000:~$ dpkg -l | grep ssh ii libssh2-1:amd641.4.3-4.1+deb8u1amd64 SSH2 client-side library ii openssh-client 1:6.7p1-5+deb8u3amd64 secure shell (SSH) client, for secure access to remote machines ii openssh-server 1:6.7p1-5+deb8u3amd64 secure shell (SSH) server, for secure access from remote machines ii openssh-sftp-server1:6.7p1-5+deb8u3amd64 secure shell (SSH) sftp server module, for SFTP access from remote machines ii python-paramiko1.15.1-1all Make ssh v2 connections with Python (Python 2) ii task-ssh-server3.31+deb8u1 all SSH server nick@RBMK-1000:~$