LoginSignup
1
1

More than 3 years have passed since last update.

EC2にSSh接続 ~初心者~

Posted at

はじめに

sshでのコマンドをよく忘れがち・・(記憶力がポンコツ)
認証設定、ファイル転送も含めて記載します。

準備

  • Ec2(22番ポート解放済み)
  • pemキー作成済み
  • IPアドレスが割り当ている
  • Mac(Windowsでもいけます)

ログイン

① ターミナルからSShコマンドを実行

ssh -i ***.pem ec2-user@IPアドレス

② レスポンス、ログイン完了

The authenticity of host 'IPアドレス(IPアドレス)' can't be established.
ECDSA key fingerprint is SHA256:/RFBylrcFvYgOKPPq/GTRP4Hj+rZgH4pWEwArsW7lxk.
Are you sure you want to continue connecting (yes/no)? y

       __|  __|_  )
       _|  (     /   Amazon Linux 2 AMI
      ___|\___|___|

https://aws.amazon.com/amazon-linux-2/
No packages needed for security; 4 packages available
Run "sudo yum update" to apply all updates.
[ec2-user@ip-192-168-100-30 ~]$

今回はAmazonLinuxにログインしたので、デフォルトのユーザ名が『ec2-user』でしたが、
ディストリビューションによってユーザー名が異なります。

RHEL の場合、ユーザー名は root または ec2-user
Ubuntu の場合、ユーザー名は ubuntu
SUSE Linux の場合、ユーザー名は root または ec2-user のいずれか

認証設定

pemキーだけのログインではセキュリティが弱いので、認証設定をします。

① アカウント作成

$ sudo useradd ec2-user2

② パスワード設定
 ※パスワードを変更する場合も上書きができます。

$ sudo passwd ec2-user2
Changing password for user ec2-user.
New password:
Retype new password:

レスポンス

passwd: all authentication tokens updated successfully.

③ /etc/ssh/sshd_config ファイルの PasswordAuthenticationパラメータの設定変更する。

sudo vi /etc/ssh/sshd_config 

PasswordAuthentication yes

④ ssh再起動する。 ※Ubuntuは異なる

sudo service sshd restart

Mac(ローカルPC)→EC2へファイル転送

①ホームディレクトリにpemファイルを転送

scp -i ***.pem ***.txt ec2-user@IPアドレス:~

レスポンス

***.txt                                                                                             100% 1692    66.2KB/s   00:00

②ホームディレクトリを確認するとファイル転送がされています。

[ec2-user@ip-192-168-100-30 ~]$ ls
***.txt

[参照]

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