Difference between revisions of "AWS"

From Ever changing code
Jump to navigation Jump to search
Line 16: Line 16:
Copy <tt>mykey.pub</tt> public PUB key to EC2 instance
Copy <tt>mykey.pub</tt> public PUB key to EC2 instance
  scp ~/.ssh/mykey.pub ubuntu@ec2-user@ec2-99-99-99-99.compute-1.amazonaws.com:/home/ubuntu/.ssh/
  scp ~/.ssh/mykey.pub ubuntu@ec2-user@ec2-99-99-99-99.compute-1.amazonaws.com:/home/ubuntu/.ssh/
Append <tt>mykey.pub</tt> to <tt>authorized_keys</tt> this is know as nstalling the public key to server  
Login to the instance and append <tt>mykey.pub</tt> to <tt>authorized_keys</tt> this is know as nstalling the public key to server  
  ssh ubuntu@ec2-user@ec2-99-99-99-99.compute-1.amazonaws.com
  ssh ubuntu@ec2-user@ec2-99-99-99-99.compute-1.amazonaws.com
  cat ~/.ssh/mykey.pub >> ~/.ssh/authorized_keys
  cat ~/.ssh/mykey.pub >> ~/.ssh/authorized_keys
===Connect to the EC2 instance===
===Connect to the EC2 instance===
*Ubuntu user: ubuntu (confirmed)
*Ubuntu user: ubuntu (confirmed)

Revision as of 13:48, 18 August 2013

ssh to EC2 instance

SSH theory using a private and public key

Your private key is created when you setup EC2 instance and is listed under EC2 Dashboard > NETWORK & SECURITY > Key Pairs, you must have downloaded a copy of the private key onto your local machine during the instance creation. The key pair used to connect to the specific instance is listed on the Instances screen > Key Pair Name:

Instance-keypair

Generate private PEM key and public PUB key on Linux client

The command below will generate private/public key pair in the current directory. The file without the extension it is private key, please cat mykey to preview. You will be prompted for passphrase what it adds an extra of security but it can be ignored by pressing [enter] twice.

ssh-keygen -t rsa

Change permissions of the key to ready only by owner as per Getting Started with Amazon EC2 Linux Instances

chmod 400 mykey.pem
-r------- 1 user user 1766 Aug 18 01:17 mykey.pem

Copy public PUB key to the EC2 instance

Copy mykey.pub public PUB key to EC2 instance

scp ~/.ssh/mykey.pub ubuntu@ec2-user@ec2-99-99-99-99.compute-1.amazonaws.com:/home/ubuntu/.ssh/

Login to the instance and append mykey.pub to authorized_keys this is know as nstalling the public key to server

ssh ubuntu@ec2-user@ec2-99-99-99-99.compute-1.amazonaws.com
cat ~/.ssh/mykey.pub >> ~/.ssh/authorized_keys

Connect to the EC2 instance

  • Ubuntu user: ubuntu (confirmed)
  • RedHat user: root (tbc)
  • Amazon branded instances: ec2-user (to be confirm)

Connecting and useful flags -l username specifies linux account user name, -v verbose mode

ssh -i mykey.pem ubuntu@ec2-user@ec2-99-99-99-99.compute-1.amazonaws.com

EC2 Security Group

Remember to assign the security group that applies to your scheme on your instance. Having port open on the instance does not mean you will be able to access from outside. It must bypass EC2 Security Group first. Overview below:

Ec2-security-group