0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

bash起動に関して

Last updated at Posted at 2021-11-29

わかりやすい説明があったので
https://blog1.mammb.com/entry/2019/12/01/090000#%E3%83%AD%E3%82%B0%E3%82%A4%E3%83%B3%E3%82%B7%E3%82%A7%E3%83%AB%E3%81%A8%E3%81%AF

なんで以下の順番でプロファイルを読み込んでいるのかわからなかった。。。

気になって調べてみた。

bashコマンドのソースに記載があった。
version:4.2

SYS_PROFILEは、「/etc/profile」のこと

shell.c

 /* Execute /etc/profile and one of the personal login shell
	 initialization files. */
      if (no_profile == 0)
	{
	  maybe_execute_file (SYS_PROFILE, 1);

	  if (act_like_sh)	/* sh */
	    maybe_execute_file ("~/.profile", 1);
	  else if ((maybe_execute_file ("~/.bash_profile", 1) == 0) &&
		   (maybe_execute_file ("~/.bash_login", 1) == 0))	/* bash */
	    maybe_execute_file ("~/.profile", 1);
	}

      sourced_login = 1;
    }
pathnames.h

/* The default login shell startup file. */
# define SYS_PROFILE "/etc/profile"

# この「SYS_PROFILE」が「/etc/profile」のこと
# 宣言は、

Redhatでログインして、psコマンドを実行すると、bashだけが実行されている。
なのでbash関連のファイルが読み込まれている。

OS上で「~.profile」を作成しただけでは、bashがまた起動された。
仕方ないので「/etc/passwd」のシェルの部分を変更した。
そうしたら「.profile」が読まれた。

ということは、ユーザがログインする際に、/etc/passwdをチェックしているんだなぁということが
わかった。
誰が犯人なんだろうって思って調査開始。

よくよく考えてみたら
Redhatのログインを制御しているのってsystemdだと仮定して再調査

/etc/passwdから以下のファイルを読んでいることがわかった。
version:systemd 219

util.c

        if (shell)
                *shell = p->pw_shell;

        return 0;
}

systemdが、ログイン時に「/etc/passwd」ファイルを読み込んで
ユーザのシェル情報を取得している。
それをもってシェル設定を行っている模様。。。。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?