この記事では、CentOS®の新規または既存のユーザーにsudoアクセスを許可するプロセスについて説明します。
-
adduser
を使用して新しいユーザーを作成します コマンドの後に新しいユーザーの<username>
次の例に示すように:[root@server-01 ~]# adduser newuser
-
passwd
を使用します コマンドの後に新しいユーザーの<username>
newuser
のパスワードを設定します 。確認プロンプトに新しいパスワードを2回入力します。[root@server-01 ~]# passwd newuser Changing password for user newuser. New password: Retype new password: passwd: all authentication tokens updated successfully
-
sudoersを編集します 次のコマンドを使用してファイルを作成します:
[root@server-01 ~]# visudo
-
次に、次のテキストのようなバージョンが表示されます。
## Next comes the main part: which users can run what software on ## which machines (the sudoers file can be shared between multiple ## systems). ## Syntax: ## ## user MACHINE=COMMANDS ## ## The COMMANDS section may have other options added to it. ## ## Allow root to run any commands anywhere root ALL=(ALL) ALL ## Allows members of the 'sys' group to run networking, software, ## service management apps and more. # %sys ALL = NETWORKING, SOFTWARE, SERVICES, STORAGE, DELEGATING, PROCESSES, LOCATE, DRIVERS ## Allows people in group wheel to run all commands %wheel ALL=(ALL) ALL ## Same thing without a password # %wheel ALL=(ALL) NOPASSWD: ALL ## Allows members of the users group to mount and unmount the ## cdrom as root # %users ALL=/sbin/mount /mnt/cdrom, /sbin/umount /mnt/cdrom ## Allows members of the users group to shutdown this system # %users localhost=/sbin/shutdown -h now ## Read drop-in files from /etc/sudoers.d (the # here does not mean a comment) #includedir /etc/sudoers.d
-
iを押します キーボードのキーを押して挿入モードに入ります。次にjを押します キーを押してカーソルを下に移動し、 k キーを押して次のセクションに移動します:
## Allow root to run any commands anywhere root ALL=(ALL) ALL
-
<username> ALL=(ALL) ALL
を挿入して、新しく作成したユーザーを追加します 次の例に示すように、新しい行に:## Allow root to run any commands anywhere root ALL=(ALL) ALL newuser ALL=(ALL) ALL
-
iを押します キーを押して挿入モードを終了し、:wqと入力します 保存して終了します。
-
su
を使用する コマンドの後に- <username>
が続きます 新しいユーザーアカウントにアクセスします。[root@server-01 ~]# su - newuser [newuser@server-01 ~]$
-
sudo -i
を使用します 新しいユーザーアカウントが権限を昇格できるかどうかをテストするコマンド。新しいユーザーのパスワードを入力します。次の例を使用して、これらの手順を確認します。[newuser@server-01 ~]$ sudo -i 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 newuser: [root@server-01 ~]#
-
whoami
を使用する 現在rootユーザーであることを確認するコマンド。[root@server-01 ~]# whoami root