selinux: /home のファイルが無効なコンテキストを使用して生成されました。

selinux: /home のファイルが無効なコンテキストを使用して生成されました。

Cents 7の/ homeに無効なフォルダ/ファイルコンテキストが生成されました。

# pwd
/home
# ls
# ls -dZ .
drwxr-xr-x. root root system_u:object_r:home_root_t:s0 .
# mkdir -p test/.ssh
# touch test/.ssh/authorized_keys
# ls -ldZ test test/.ssh
drwxr-xr-x. root root unconfined_u:object_r:home_root_t:s0 test
drwxr-xr-x. root root unconfined_u:object_r:home_root_t:s0 test/.ssh
-rw-r--r--. root root unconfined_u:object_r:home_root_t:s0 test/.ssh/authorized_keys
#

最初のsshログインがユーザーのホームフォルダを作成しても同じ問題が発生します(selinuxが文句を言うため、ユーザーはsshキーを使用して権限を付与できません)。

root ユーザーが存在する場合、コンテキストの問題は存在しません。su ユーザーを選択し、正しいコンテキストでホームフォルダを作成します。

学ぶ方法SSHD/SSHセッションは適切なコンテキストで新しいユーザーのホームディレクトリを作成しますか?

いいえ。問題を解決するには、ユーザーは以下を実行する必要があります。復元制御コマンド、例:

# ls -ldZ test/.ssh/authorized_keys test test/.ssh
drwxr-xr-x. root root unconfined_u:object_r:home_root_t:s0 test
drwxr-xr-x. root root unconfined_u:object_r:home_root_t:s0 test/.ssh
-rw-r--r--. root root unconfined_u:object_r:home_root_t:s0 test/.ssh/authorized_keys
# restorecon -vR test
restorecon reset /home/test context unconfined_u:object_r:home_root_t:s0->unconfined_u:object_r:user_home_dir_t:s0
restorecon reset /home/test/.ssh context unconfined_u:object_r:home_root_t:s0->unconfined_u:object_r:ssh_home_t:s0
restorecon reset /home/test/.ssh/authorized_keys context unconfined_u:object_r:home_root_t:s0->unconfined_u:object_r:ssh_home_t:s0
# ls -ldZ test/.ssh/authorized_keys test test/.ssh
drwxr-xr-x. root root unconfined_u:object_r:user_home_dir_t:s0 test
drwxr-xr-x. root root unconfined_u:object_r:ssh_home_t:s0 test/.ssh
-rw-r--r--. root root unconfined_u:object_r:ssh_home_t:s0 test/.ssh/authorized_keys
#

ベストアンサー1

おすすめ記事