aws ec2 Ubuntu 18.04.1 LTS ユーザー追加 ssh sftp接続
ユーザー作成
ec2 Ubuntu 18.04.1 LTS
作成時のubuntuユーザーから新規ユーザーを作成する。
sudo adduser [ユーザー名]
adduserを実行すると下記の表示されます。
Adding user `[ユーザー名]' ... Adding new group `[ユーザー名]' (1001) ... Adding new user `[ユーザー名]' (1001) with group `[ユーザー名]' ... Creating home directory `/home/[ユーザー名]' ... Copying files from `/etc/skel' ... Enter new UNIX password: [パスワードはてきとう] Retype new UNIX password: passwd: password updated successfully Changing the user information for [ユーザー名] Enter the new value, or press ENTER for the default Full Name []: [ユーザー名] taro Room Number []: Work Phone []: Home Phone []: Other []: Is the information correct? [Y/n] Y
パスワードなど入力する必要があります。
ユーザー切替
sudo su [ユーザー名]
ssh用ディレクトリ作成
新しく作成したユーザーのホームディレクトリに移動しssh用のディレクトリを作成する。
cd /home/[ユーザー名] mkdir .ssh
rsa鍵ペアを作成
cd .ssh ssh-keygen -t rsa
ssh-keygenを実行すると下記が表示され
id_rsa
id_rsa.pub
2つファイルができます。
Generating public/private rsa key pair. Enter file in which to save the key (/home/[ユーザー名]/.ssh/id_rsa): Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /home/[ユーザー名]/.ssh/id_rsa. Your public key has been saved in /home/[ユーザー名]/.ssh/id_rsa.pub. The key fingerprint is: SHA256:******** [ユーザー名] The key's randomart image is: +---[RSA 2048]----+ | . . | | + o | |. ++ . | |oo+oo. o . | |.+=== B S | |.=** B = | |o+Oo* o | |.o+=oE. | | ...++ | +----[SHA256]-----+
id_rsa
id_rsa.pub
がある.ssh
ディレクトリ上にauthorized_keys
を作成する。
# id_rsa.pubをコピー
cp id_rsa.pub authorized_keys
authorized_keysができます。
下記のファイルとディレクトリ権限変更します。
chmod 600 authorized_keys chmod 700 .ssh
ローカルPC上でssh接続テスト
id_rsaを自分のPCにコピー
ssh -i "ローカルにコピーしたid_rsaファイル" [ユーザー名]@aws_ec2の接続先