GNU/Linux >> Linux の 問題 >  >> Linux

CentOSでsudoユーザーを作成する

この記事では、CentOS®の新規または既存のユーザーにsudoアクセスを許可するプロセスについて説明します。

新しいユーザーを作成する
  1. adduserを使用して新しいユーザーを作成します コマンドの後に新しいユーザーの<username> 次の例に示すように:

     [root@server-01 ~]# adduser newuser
    
  2. 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
    
新規または既存のユーザーにroot権限を付与する
  1. sudoersを編集します 次のコマンドを使用してファイルを作成します:

     [root@server-01 ~]# visudo
    
  2. 次に、次のテキストのようなバージョンが表示されます。

    ## 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
    
  3. iを押します キーボードのキーを押して挿入モードに入ります。次にjを押します キーを押してカーソルを下に移動し、 k キーを押して次のセクションに移動します:

     ## Allow root to run any commands anywhere
     root    ALL=(ALL)       ALL
    
  4. <username> ALL=(ALL) ALLを挿入して、新しく作成したユーザーを追加します 次の例に示すように、新しい行に:

    ## Allow root to run any commands anywhere
    root    ALL=(ALL)       ALL
    newuser ALL=(ALL)       ALL
    
  5. iを押します キーを押して挿入モードを終了し、:wqと入力します 保存して終了します。

権限の変更を確認する
  1. suを使用する コマンドの後に- <username>が続きます 新しいユーザーアカウントにアクセスします。

     [root@server-01 ~]# su - newuser
     [newuser@server-01 ~]$ 
    
  2. 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 ~]# 
    
  3. whoamiを使用する 現在rootユーザーであることを確認するコマンド。

     [root@server-01 ~]# whoami
     root
    

Linux
  1. DebianでSudoユーザーを作成する方法

  2. DebianでSudoユーザーを作成する-ステップバイステップのプロセス?

  3. Centos – CentosでSftpユーザーを作成する方法は?

  1. CentOS7でsudoユーザーを作成する方法

  2. CentOS8でシェルアクセスなしでSFTPユーザーを作成する方法

  3. RockyLinux8でSudoユーザーを作成する方法

  1. CentOS、Ubuntu、DebianでSudoユーザーを作成する方法

  2. RockyLinuxおよびCentOSでSudoユーザーを作成する方法

  3. Ubuntuでsudoユーザーを作成する