[Linux]: SSH between two EC2 hosts
Using username “ec2-user”.
Authenticating with public key “imported-openssh-key”
Last login: Fri May 8 12:23:16 2015 from 49.205.126.24
__| __|_ )
_| ( / Amazon Linux AMI
___|\___|___|
https://aws.amazon.com/amazon-linux-ami/2015.03-release-notes/
11 package(s) needed for security, out of 36 available
Run “sudo yum update” to apply all updates.
[ec2-user@ip-10-0-0-197 ~]$ pwd
/home/ec2-user
[ec2-user@ip-10-0-0-197 ~]$ ll -lhtra .ssh/
total 12K
-rw——- 1 ec2-user ec2-user 407 May 8 11:53 authorized_keys
drwx—— 2 ec2-user ec2-user 4.0K May 8 11:53 .
drwx—— 3 ec2-user ec2-user 4.0K May 8 12:28 ..
[ec2-user@ip-10-0-0-197 ~]$
[ec2-user@ip-10-0-0-197 ~]$
[ec2-user@ip-10-0-0-197 ~]$ cd .ssh/
[ec2-user@ip-10-0-0-197 .ssh]$
[ec2-user@ip-10-0-0-197 .ssh]$
[ec2-user@ip-10-0-0-197 .ssh]$
[ec2-user@ip-10-0-0-197 .ssh]$
[ec2-user@ip-10-0-0-197 .ssh]$ vi ec2-user.pem // copy your keypair (.pem) content here
[ec2-user@ip-10-0-0-197 .ssh]$
[ec2-user@ip-10-0-0-197 .ssh]$ sudo su
[root@ip-10-0-0-197 .ssh]# pwd
/home/ec2-user/.ssh
[root@ip-10-0-0-197 .ssh]# chmod 400 ec2-user.pem // change file permissions to 400
[root@ip-10-0-0-197 .ssh]#
[root@ip-10-0-0-197 .ssh]#
[root@ip-10-0-0-197 .ssh]# ll -lhtr
total 12K
-rw——- 1 ec2-user ec2-user 407 May 8 11:53 authorized_keys
-r——– 1 ec2-user ec2-user 1.7K May 8 12:32 ec2-user.pem
-rw-r–r– 1 ec2-user ec2-user 222 May 8 12:33 known_hosts
[root@ip-10-0-0-197 .ssh]#
[root@ip-10-0-0-197 .ssh]#
[root@ip-10-0-0-197 .ssh]# exit
[ec2-user@ip-10-0-0-197 .ssh]$
[ec2-user@ip-10-0-0-197 .ssh]$
[ec2-user@ip-10-0-0-197 .ssh]$ ssh -i ec2-user.pem ec2-user@52.6.50.210 // now try to ssh with keypair
Last login: Fri May 8 12:34:31 2015 from 52.7.8.107
__| __|_ )
_| ( / Amazon Linux AMI
___|\___|___|
https://aws.amazon.com/amazon-linux-ami/2015.03-release-notes/
11 package(s) needed for security, out of 36 available
Run “sudo yum update” to apply all updates.
[ec2-user@ip-10-0-0-28 ~]$
[ec2-user@ip-10-0-0-28 ~]$
[ec2-user@ip-10-0-0-28 ~]$ cd .ssh/
[ec2-user@ip-10-0-0-28 .ssh]$
[ec2-user@ip-10-0-0-28 .ssh]$
[ec2-user@ip-10-0-0-28 .ssh]$
[ec2-user@ip-10-0-0-28 .ssh]$ pwd
/home/ec2-user/.ssh
[ec2-user@ip-10-0-0-28 .ssh]$
[ec2-user@ip-10-0-0-28 .ssh]$
[ec2-user@ip-10-0-0-28 .ssh]$ ll -lhtra
total 20K
-rw——- 1 ec2-user ec2-user 407 May 8 11:54 authorized_keys
drwx—— 3 ec2-user ec2-user 4.0K May 8 12:07 ..
-rw-r–r– 1 ec2-user ec2-user 403 May 8 12:48 ec2-user.pub
-rw——- 1 ec2-user ec2-user 1.7K May 8 12:48 ec2-user
drwx—— 2 ec2-user ec2-user 4.0K May 8 12:48 .
[ec2-user@ip-10-0-0-28 .ssh]$
[ec2-user@ip-10-0-0-28 .ssh]$ vi ec2-user.pem
[ec2-user@ip-10-0-0-28 .ssh]$
[ec2-user@ip-10-0-0-28 .ssh]$ chmod 400 ec2-user.pem
[ec2-user@ip-10-0-0-28 .ssh]$
[ec2-user@ip-10-0-0-28 .ssh]$
[ec2-user@ip-10-0-0-28 .ssh]$
[ec2-user@ip-10-0-0-28 .ssh]$ scp -i ec2-user.pem ec2-user.pub ec2-user@52.7.8.107:/home/ec2-user/
ec2-user.pub 100% 403 0.4KB/s 00:00
[ec2-user@ip-10-0-0-28 .ssh]$
[ec2-user@ip-10-0-0-28 .ssh]$ ll -lhtra
total 28K
-rw——- 1 ec2-user ec2-user 407 May 8 11:54 authorized_keys
-rw-r–r– 1 ec2-user ec2-user 403 May 8 12:48 ec2-user.pub
-rw——- 1 ec2-user ec2-user 1.7K May 8 12:48 ec2-user
-r——– 1 ec2-user ec2-user 1.7K May 8 12:50 ec2-user.pem
drwx—— 3 ec2-user ec2-user 4.0K May 8 12:50 ..
-rw-r–r– 1 ec2-user ec2-user 222 May 8 12:51 known_hosts
drwx—— 2 ec2-user ec2-user 4.0K May 8 12:51 .
[ec2-user@ip-10-0-0-28 .ssh]$