LoginSignup
1
1

More than 3 years have passed since last update.

Ubuntuでubuntuユーザ以外のアカウントでSSHログインできるようにする

Last updated at Posted at 2019-07-17

クライアント:MacOS High Sierra
サーバ:16.04.6 LTS (Xenial Xerus)
AWS EC2 で構築したため、ubuntuユーザのキーペアがあらかじめ作成されています。
クライアントPC側はAWSで生成したキーペアを使用しています。

Ubuntuの初期アカウントのubuntuでSShします。
クライアント

$ ssh -i aws.pem ubuntu@y.y.y.y

サーバ

$ sudo su

アカウント作成

# useradd xxxx
# passwd xxxx

sudoユーザへの追加

# groups xxxx
   xxxx : xxxx
# gpasswd -a xxxx sudo
   Adding user xxxx to group sudo
# groups xxxx
   xxxx : xxxx sudo

ユーザディレクトリの作成

# mkdir /home/xxxx
# midir /home/xxxx/.ssh

鍵の設置

今回はubuntuユーザと同じ鍵を設置することとします。

# ls -l /home/ubuntu/.ssh/
    total 4
    -rw------- 1 ubuntu ubuntu 392 Jul 17 15:39 authorized_keys
# cp /home/ubuntu/.ssh/authorized_keys /home/xxxx/.ssh/authorized_keys
# diff /home/ubuntu/.ssh/authorized_keys /home/xxxx/.ssh/authorized_keys
# chmod 600 /home/xxxx/.ssh/authorized_keys
# chown xxxx:xxxx /home/xxxx/.ssh/authorized_keys

クライアント

$ ssh -i aws.pem xxxx@y.y.y.y
    Welcome to Ubuntu 16.04.6 LTS (GNU/Linux 4.4.0-1087-aws x86_64)
$ 

※ cat /etc/ssh/sshd_configの PermitRootLogin prohibit-password については、PermitRootLogin no としてもよい。

# vi /etc/ssh/sshd_config
# /etc/init.d/ssh restart
    [ ok ] Restarting ssh (via systemctl): ssh.service
1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1