LoginSignup
8
6

More than 3 years have passed since last update.

AWS EC2インスタンスへのSSH接続の仕方

Last updated at Posted at 2019-07-27

AWS EC2へのSSH接続の仕方

今更だが、AWSに触ったキッカケはServerlessアプリを作るところからだったのでEC2を使うのが始めてだったりする。備忘録。マイマシンはubuntu18.04です。

AWSでEC2インスタンスを作成

なんでもいいけど
"Ubuntu Server 16.04 LTS (HVM), SSD Volume Type - ami-bec974d8"で作成した。t2.microというタイプ。ウィザードは全部デフォルト。これだと月に10ドルくらい。
AWS 月額料金チートシート
最後に.pemファイルをダウンロードすること。キー名というのを設定するがそれがpemファイルの名前になるだけ。

.pemファイルのアクセス権を変更

.pem ファイルを自分のマシンの適当な場所に移動して(たとえば~/pathフォルダなどを作る)、そこに対するアクセス許可を0777 ではなく 0400にする。

$ cd ~/
$ mkdir path
$ mv ***.pem path
$ chmod 400 path

sshで接続

以下のコマンド。

$ sudo ssh -i path/***.pem ubuntu@ec2-11-11-111-111.ap-northeast-1.compute.amazonaws.com
@の前のデフォルトユーザ名は以下の通り。

Screenshot from 2019-07-27 18-04-41.png
https://docs.aws.amazon.com/ja_jp/AWSEC2/latest/UserGuide/connection-prereqs.html

以下のようなレスポンスが来て、yesと答えると、

The authenticity of host 'ec2-111-11-111-1.compute-1.amazonaws.com (10.254.142.33)'
can't be established.
RSA key fingerprint is 1f:51:ae:.
Are you sure you want to continue connecting (yes/no)?

こう返ってくる。

Warning: Permanently added 'ec2-111-11-111-1.compute-1.amazonaws.com' (RSA) 
to the list of known hosts.

プロンプトはこうなっているはず。繋がった。

ubuntu@ip-111-11-11-111:~$

rootユーザーになるには?

rootのパスワードは設定されていない。次のコマンドでrootになれる。

~$ sudo su -

作業を終えたらexitコマンド。


ファイルをEC2へアップロードする

Googleのdebパッケージをアップロードするには下記のコマンド

sudo scp -i path/***.pem google-chrome-stable_current_amd64.deb ubuntu@ec2-1-111-11-111.ap-northeast-1.compute.amazonaws.com:/home/ubuntu

直接EC2からこれでも良い。


wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
8
6
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
8
6