когда ssh запускается с аргументом server + command, какой профиль запуска запускается, если таковой имеется?

Портативный ноутбук Steampunk за 5000 $

enter image description here

1
задан 7 April 2015 в 03:36

1 ответ

Без команды SSH запускает оболочку входа. Для bash, который включает поиск .profile (который на Ubuntu, источники .bashrc) (и /etc/profile, какие источники /etc/bash.bashrc). Существуют и другие файлы, которые могли бы быть использованы, например .bash_profile, но настройка Ubuntu по умолчанию имеет только .profile.

$ grep bashrc /etc/profile .profile
/etc/profile:    # The file bash.bashrc already sets the default PS1.
/etc/profile:    if [ -f /etc/bash.bashrc ]; then
/etc/profile:      . /etc/bash.bashrc
.profile:    # include .bashrc if it exists
.profile:    if [ -f "$HOME/.bashrc" ]; then
.profile:   . "$HOME/.bashrc

При запуске с помощью команды SSH не запускает логин shell, поэтому в соответствии с man bash (раздел INVOCATION):

When an interactive shell that is not a login shell  is  started,  bash
reads  and  executes  commands  from /etc/bash.bashrc and ~/.bashrc, if
these files exist.  This may be inhibited by using the  --norc  option.
The  --rcfile  file option will force bash to read and execute commands
from file instead of /etc/bash.bashrc and ~/.bashrc.

Однако команда bash не запускается в интерактивном режиме. Тогда почему .bashrc источник? Опять же, из man bash:

Bash attempts to determine when it is being run with its standard input
connected to a network connection, as when executed by the remote shell
daemon, usually rshd,  or  the  secure  shell  daemon  sshd.   If  bash
determines  it  is  being  run  in  this fashion, it reads and executes
commands from ~/.bashrc and ~/.bashrc, if these  files  exist  and  are
readable.  It will not do this if invoked as sh.  The --norc option may
be used to inhibit this behavior, and the --rcfile option may  be  used
to  force  another file to be read, but neither rshd nor sshd generally
invoke the shell with those options or allow them to be specified.

Другие файлы могут быть прочитаны SSH (из man bash , раздел FILES):

~/.ssh/rc
     Commands in this file are executed by ssh when the user logs in,
     just before the user's shell (or command) is started.  See the
     sshd(8) manual page for more information.
/etc/ssh/sshrc
     Commands in this file are executed by ssh when the user logs in,
     just before the user's shell (or command) is started.  See the
     sshd(8) manual page for more information.

Для переменных среды (из man ssh, раздел ENVIRONMENT):

Additionally, ssh reads ~/.ssh/environment, and adds lines of the format
“VARNAME=value” to the environment if the file exists and users are
allowed to change their environment.  For more information, see the
PermitUserEnvironment option in sshd_config(5).

Модуль pam_env включен для SSH:

$ grep pam_env /etc/pam.d/sshd 
# /etc/security/pam_env.conf.
session    required     pam_env.so # [1]
session    required     pam_env.so user_readenv=1 envfile=/etc/default/locale

, переменные в /etc/environment и ~/.pam_environment также установлены (и /etc/default/locale, так как envfile установлен). Тем не менее, эти файлы не являются источниками .profile, поэтому вы не можете использовать команды оболочки здесь.

1
ответ дан 23 May 2018 в 21:40

Другие вопросы по тегам:

Похожие вопросы: