Setting up SSH to EC2 Instances
# For existing/running instances:
- Navigate to “Key Pairs” in the AWS EC2 console menu.
- Create Key pair - name it something memorable or it will default to
id_rsa.pem
. Check.pem
when prompted on the key file format.- The browser will automatically download the private key file.
- On Mac/linux, use the following command:
ssh-keygen -y
- Then provide the path to the private key file when prompted.
- The public key will be output.
- Connect to the existing instance using
EC2 Instance Connect
. - Navigate to the
.ssh
folder, and open the.ssh/authorized_keys
file on the instance. - Paste the public key information from your new key pair underneath the existing public key information. Save the file.
- Disconnect from your instance, and test that you can connect to your instance using the new private key file.
- From ubuntu, you can run the
ssh
command with the-i
flag to specify the private key. e.g:ssh -i your-key-ssh.pem ec2-user@13.0.0.1
- From ubuntu, you can run the
If you’re replacing an existing key pair, connect to your instance and delete the public key information for the original key pair from the
.ssh/authorized_keys
file.
# For new instances:
# Setting up SFTP
After a bunch of trial attempts, Filezilla wouldn’t authenticate properly for me (configured keys, paths, permissions and auth methods several times). Ended up just using SFTP through terminal as suggested here.
# Steps:
Connect with the EC2 Instance with:
|
|
# Downloading files / dirs
To download path/to/source/file.txt
and path/to/source/dir
:
|
|
# Uploading files / dirs
To upload localpath/to/source/file.txt
and ~/localpath/to/source/dir
to remotepath/to/dest
:
|
|
# Resources:
- https://stackoverflow.com/questions/45198768/how-to-find-aws-keypair-public-key
- https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/create-key-pairs.html#having-ec2-create-your-key-pair
- https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/replacing-key-pair.html
- https://www.cyberciti.biz/faq/how-to-install-ssh-on-ubuntu-linux-using-apt-get/