I'm experiencing a strange behavior on some of our machines atm. At least, it seems strange to me and my colleagues and we didn't find any explanation for it 🙂
[edit 1]
Next paragraph seems to be wrong. See edit 2 at end.
We're using bash and zsh here. So, when SSHing into some of the zsh-default-machines (plain ssh login@host
) which are configured to use zsh as default shell (with chsh -s /usr/bin/zsh
), the then-opened shell is an interactive but non-login shell, regardless if we're already logged in on the respective machine or not.
In my understanding, SSHing into a machine should be starting a new user session on that machine, thus requiring the shell to be a login shell, right? Shouldn't that be the case for zsh, too?
When changing the default shell to bash on the machines, logging into the machine uses a login-shell.
Is this the normal behavior for zsh? Could it be changed? Or is it some misconfiguration?
[/edit 1]
[edit 2]
Ok, according to the ZSH documentation you could easily test if it is a login shell or not:
$ if [[ -o login ]]; then; print yes; else; print no; fi
See: http://zsh.sourceforge.net/Guide/zshguide02.html
However, due to zsh man entry / documentation, zsh should source /etc/profile
which in turn sources the scripts under /etc/profile.d/*.sh
. My question above originated in the fact, that the scripts are not sourced and thus most of our environment variables and system configuration stuff isn't properly initialized. However, as described above – when we're using bash as default shell, /etc/profile
and the scripts in the profile.d-folder are sourced.
[/edit 2]
[edit 3 – ANSWER]
Thx @StéphaneChazelas for the answer in the comments below!
It seems zsh
is only sourcing /etc/profile
when running in sh
/ksh
compatibility mode (see the respecitve man entry https://linux.die.net/man/1/zsh).
As logging in via SSH doesn't trigger that compatibility mode, zsh
doesn't necessarily source /etc/profile
on it's own but have to be triggered via .zprofile
[/edit 3]
System:
OS: Ubuntu 18.04
zsh-5.4.2 with omz and some plugins activated.
Thank you!
Best Answer
ZSH just works in this way.
/etc/profile
is NOT an init file for ZSH. ZSH uses/etc/zprofile
and~/.zprofile
.Init files for ZSH:
/etc/zshenv
~/.zshenv
/etc/zprofile
~/.zprofile
/etc/zshrc
~/.zshrc
/etc/zlogin
~/.zlogin
References