CentOSでユーザーを追加して、管理者権限を付与する
ユーザーを追加する
useradd dev1
パスワードを設定
passwd dev1
で入力したら、パスワード設定ができる。
ユーザーのリストを確認
# cat /etc/passwd|sed -e 's/:.*//g' root (省略) nginx apache dev1
管理者権限を付与する
visudo
で /etc/sudoer を開く
%wheel ALL=(ALL) ALL
これは、wheelグループに所属していたら、全てのコマンドの実行権限があるぜ、という意味だそうです。
(実行元ユーザー or %実行元グループ) 接続元=(実行先ユーザー:実行先グループ) 実行可能なコマンド
レファレンス元: https://qiita.com/kaito_program/items/e6a6013b1f614eed1960
試しに、権限を付与する前に、作ったユーザーでログインし、下記コマンドを実行しました。
ls /root/
すると、
ls: cannot open directory '/root/': Permission denied
と出ました!
また、
sudo ls /root/
と打ったみたところ、
We trust you have received the usual lecture from the local System Administrator. It usually boils down to these three things: #1) Respect the privacy of others. #2) Think before you type. #3) With great power comes great responsibility.
その上で、パスワードを求められたので、入力したところ、
[sudo] password for dev1: dev1 is not in the sudoers file. This incident will be reported.
と出ました!
「sudoできる人の中に入っていないよ。インシデントとして報告します!」
ということですね! なるほど〜。
(改めて)管理者権限を付与する
usermod -G wheel <ユーザ名>
作ったユーザーにスイッチして、試してみます。
# sudo su - dev1
$ ls /root/
してみると、相変わらず権限なしで見られません。
ls: cannot open directory '/root/': Permission denied
$ sudo ls /root/
これで、パスワードを聞かれ、パスワードを入れると、今回は中身が見れました!