この記事では、Ubuntu®オペレーティングシステムの新規または既存のユーザーにsudoアクセスを許可する方法について説明します。
-
adduserを使用する コマンドの後に新しい<username>が続きます :root@server-01:~# adduser newuser Adding user `newuser' ... Adding new group `newuser' (1001) ... Adding new user `newuser' (1001) with group `newuser' ... Creating home directory `/home/newuser' ... Copying files from `/etc/skel' ... -
プロンプトで、新しいユーザーのパスワードを2回入力して設定し、確認します。
New password: Retype new password: passwd: password updated successfully -
新しいユーザーの連絡先情報を追加する場合は、プロンプトで入力し、 ENTERを押します。 デフォルトを続行します。終了したら、
yと入力します 入力した情報が正しいことを確認するには:Changing the user information for newuser Enter the new value, or press ENTER for the default Full Name []: New Hire Room Number []: Work Phone []: Home Phone []: Other []: Is the information correct? [Y/n] y
-
visudoを使用する sudoersを編集するには ファイル。root@server-01:~# visudo -
次の例のようなテキストが表示されます:
GNU nano 4.8 /etc/sudoers.tmp # # This file MUST be edited with the 'visudo' command as root. # # Please consider adding local content in /etc/sudoers.d/ instead of # directly modifying this file. # # See the man page for details on how to write a sudoers file. # Defaults env_reset Defaults mail_badpass Defaults secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:> # Host alias specification # User alias specification # Cmnd alias specification # User privilege specification root ALL=(ALL:ALL) ALL # Members of the admin group may gain root privileges %admin ALL=(ALL) ALL # Allow members of group sudo to execute any command %sudo ALL=(ALL:ALL) ALL # See sudoers(5) for more information on "#include" directives: #includedir /etc/sudoers.d -
下矢印を使用します キーを押して次のセクションにスクロールします:
# User privilege specification root ALL=(ALL:ALL) ALL -
<username> ALL=(ALL:ALL) ALLを挿入して、新しく作成したユーザーを追加します 次の例に示すように、ユーザー特権セクションの最後にあります。# User privilege specification root ALL=(ALL:ALL) ALL newuser ALL=(ALL:ALL) ALL -
Ctrl xを押します 出る。
yと入力します 保存するには、 ENTERをクリックします 終了します。
-
suを使用する 続いて<username>新しいユーザーアカウントに切り替えるには:root@server-01:~# su - newuser newuser@server-01:~$ -
sudo -iを使用します ユーザーアカウントが権限を昇格できることを確認します。プロンプトで、新しいユーザーのパスワードを入力します。newuser@server-01:~$ sudo -i [sudo] password for newuser: root@server-01:~# -
whoamiを使用する 現在rootユーザーであることを確認するには:root@server-01:~# whoami root
コメントや質問をするには、[フィードバック]タブを使用します。私たちと会話を始めることもできます。