■ はじめに
https://dk521123.hatenablog.com/entry/2016/06/26/233349
の続き。 今回は、Root 権限 に関わるコマンドおよび その周辺の技術事項について触れる
目次
【1】suコマンド 1)ユーザを切り替えるには 2)「-」ありとなしの違い 3)su を有効にする場合 【2】sudoコマンド 【3】chmodコマンド 【4】chownコマンド 【5】その他の技術事項 1)wheel グループ 2)root に関するコマンド例
【1】suコマンド
* ユーザーを切り替える * 管理者権限に切り替える * su = Switch User の略
Options
Options | Explanation | Memo |
---|---|---|
-l, - | ログイン・シェルを使用してユーザ切替 | e.g. su - other_user |
-c | ユーザ切り替え後、commnadを実行する |
1)ユーザを切り替えるには
su -l 【ユーザ】 -c "【コマンド】"
2)「-」ありとなしの違い
su other_user
# 元のユーザの環境変数が引き継がれない。(新規ログインと同じ)
su - other_user
3)su を有効にする場合
sudo abrt-auto-reporting enabled
【2】sudoコマンド
以下の関連記事を参照のこと。
sudoコマンド
https://dk521123.hatenablog.com/entry/2016/10/22/165317
【3】chmodコマンド
* パーミッションの変更 * chmod = CHange MODe * パーミッションに関する詳細は、以下の関連記事を参照
Linux ~ パーミッション / アクセス権限 ~
https://dk521123.hatenablog.com/entry/2022/07/01/000000
【4】chownコマンド
* 所有者の変更 * chown = CHange OWNer
コマンド例
# 空ファイル作成 $ touch test.txt $ ls -l -rw-rw-r-- 1 user1 user1 0 Feb 23 20:13 test.txt << 所有者は user1 $ sudo chown root:root test.txt $ ls -l -rw-rw-r-- 1 root root 0 Feb 23 20:13 test.txt << 所有者が root になった # ディレクトリ配下の全てファイルを変更する場合 # sudo chown -R root:root test_dir # 編集しようとしても readonly モードで書き込みできない $ vim test.txt
【5】その他の技術事項
1)wheel グループ
* wheel グループのメンバーのみ rootと同様の権限を与えることができる
http://qiita.com/shimohiko/items/ce59af60a6cea38ce0cd
wheel グループの設定方法
* 以下のサイトを参照。
http://qiita.com/shimohiko/items/f45d02bea949f1f5cc85
http://www.websec-room.com/2014/01/18/1590
2)root に関するコマンド例
例1:root ユーザーのログインをロックする
passwd -l root sudo usermod -L root
例2:元に戻す
usermod -U root # 変更されたか確認 sudo cat /etc/shadow
http://takuya-1st.hatenablog.jp/entry/20120828/1346186699
http://kazmax.zpp.jp/linux/account_lock.html
関連記事
Linux ~ ユーザに関わるコマンド ~
https://dk521123.hatenablog.com/entry/2016/06/26/233349
Linux ~ パーミッション / アクセス権限 ~
https://dk521123.hatenablog.com/entry/2022/07/01/000000
sudoコマンド
https://dk521123.hatenablog.com/entry/2016/10/22/165317
シェル ~ あれこれ編 ~
https://dk521123.hatenablog.com/entry/2018/03/03/210642
シェル ~ Shebang ~
https://dk521123.hatenablog.com/entry/2024/02/02/000000
Linux ~ 環境変数あれこれ ~
https://dk521123.hatenablog.com/entry/2015/07/16/103501