【Ubuntu】sudo ユーザーを作成する方法

ユーザーの作成

root ユーザーに昇格します。

ubuntu@xx1-234-56789:~$ sudo su -

「adduser ユーザー名」でユーザーを作成します。

root@xx1-234-56789:~# adduser adminvps
Adding user `adminvps' ...
Adding new group `adminvps' (1002) ...
Adding new user `adminvps' (1002) with group `adminvps' ...
Creating home directory `/home/adminvps' ...
Copying files from `/etc/skel' ...
New password: 
Retype new password: 
passwd: password updated successfully
Changing the user information for adminvps
Enter the new value, or press ENTER for the default
	Full Name []: 
	Room Number []: 
	Work Phone []: 
	Home Phone []: 
	Other []: 
Is the information correct? [Y/n] Y
root@xx1-234-56789:~#

sudo グループに追加

このユーザーで sudo コマンドが使える様、sudo グループに追加します。

root@xx1-234-56789:~# gpasswd -a adminvps sudo
Adding user adminvps to group sudo
root@xx1-234-56789:~#

「exit」で root から出ます。

root@xx1-234-56789:~# exit
logout
ubuntu@xx1-234-56789:~$

今追加したユーザーで接続してみます。質問に「yes」と回答してパスワードを入力すると無事新ユーザーで接続ができます。

ubuntu@xx1-234-56789:~$ ssh adminvps@xx1-234-56789.vs.sakura.ne.jp
The authenticity of host '@xx1-234-56789 (127.0.1.1)' can't be established.
ECDSA key fingerprint is QWE123:QWERTYUIOPASD+QWERTYUIOP+ZXCVBNM.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added 'xx1-234-56789' (ECDSA) to the list of known hosts.
adminvps@xx1-234-56789's password: 
Welcome to Ubuntu 20.04.2 LTS (GNU/Linux 5.4.0-70-generic x86_64)

 * Documentation:  https://help.ubuntu.com
 * Management:     https://landscape.canonical.com
 * Support:        https://ubuntu.com/advantage

  System information as of Fri Apr  9 19:43:32 JST 2021

  System load:  0.0               Processes:             119
  Usage of /:   2.6% of 94.43GB   Users logged in:       1
  Memory usage: 18%               IPv4 address for ens3: 133.125.39.81
  Swap usage:   0%

 * Introducing self-healing high availability clusters in MicroK8s.
   Simple, hardened, Kubernetes for production, from RaspberryPi to DC.

     https://microk8s.io/high-availability

0 updates can be installed immediately.
0 of these updates are security updates.



The programs included with the Ubuntu system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Ubuntu comes with ABSOLUTELY NO WARRANTY, to the extent permitted by
applicable law.


SAKURA internet [Virtual Private Server SERVICE]

To run a command as administrator (user "root"), use "sudo <command>".
See "man sudo_root" for details.

adminvps@xx1-234-56789:~$