How do I connect to a new Amazon Lightsail instance from my Mac?
Asked Answered
E

4

17

I've created a new NodeJS instance on Amazon Lightsail, and wish to connect to it from my Mac's command line. Not sure how to include the required SSH key in the connection command when it says Permission denied (publickey).

Europeanize answered 4/9, 2017 at 0:18 Comment(0)
E
42
  1. Go to the "SSH Keys" tab under your Lightsail Account page
  2. Select the Default option under your region and download the key pair file
    • Will be a .pem file, ex. LightsailDefaultPrivateKey-us-west-2.pem
  3. Open up your terminal and navigate to the directory where the above file is stored
  4. Run chmod 600 [fileName] at the command line to restrict file permission so only you can read it
  5. Run ssh -i [fileName] [username]@[Public IP] to establish the connection to Lightsail
    • Username and IP are available under the "Connect" tab on the Lightsail web dashboard for your resource
Europeanize answered 4/9, 2017 at 0:18 Comment(2)
See @aleem-isiaka's answer aboveEuropeanize
user is typically [bitnami]Egomania
M
12

To use your existing ~/.ssh/id_rsa.pub

  • Login to the server using the browser client
  • Do nano ~/.ssh/authorized_keys
  • Get your local public key with xclip -sel clip < ~/.ssh/id_rsa.pub
  • Append the ~/.ssh/authorized_keys with the copied key
  • Login locally using ssh ubuntu@[instance_public_ip]
Marlette answered 4/4, 2019 at 15:21 Comment(2)
This was quite accurate, but in order to correctly append, you should do that without opening the authorized_keys file, you can try echo my_rsa_pub_string >> authorized_keys, also, there is no need to restart the instance, this was the missing part for me, now it connects like a charm, thank you.Forcefeed
This worked for me. Now I just need to figure out my password for the instanceKokand
C
7

To be able to connect to your amazon lightsail instance you need to download the key first.

  1. Go to Accounts > SSH Keys ( https://lightsail.aws.amazon.com/ls/webapp/account/keys ) > Download (Make sure that you download the key for the same region where your instance is installed.) Manage your SSH Keys

  2. Save it in a folder in your local machine. For Example- "Desktop > keys"

  3. Open the terminal and navigate to the directory where the key is stored(cd desktop/keys )

  4. Enter this command in terminal: chmod 600 keyfilename.pem (replace keyfile name with your actual key name e.g chmod 600 LightsailDefaultKey-eu-west-2.pem )

It is required that your private key files are NOT accessible by others. This is why we have to change the file permissions

  1. Run this command ssh -i keyfilename.pem username@ip replace keyfilename.pem with your actual file name, username with your username(e.g bitnami or user) and replace IP with actual IP

You can find your IP and username on your instance page (https://lightsail.aws.amazon.com/ls/webapp/home/instances > Select Instance> Manage)

Calculus answered 31/5, 2020 at 19:58 Comment(0)
D
2

I spent hours figuring out how to add an additional key to login to my Wordpress/Bitnami Lightsail Instance.

I though that by adding new key pairs in [https://lightsail.aws.amazon.com/ls/webapp/account/keys][1], I could get direct access to my instances, but that was not the case. I always got "Permission denied (publickey)" when trying to connect via SSH/SFTP.

How to solve it?

You should add your public keys directly to your Lightsail instance:

  1. Connect first to your instance via your Lightsail console. The link should looks like this: https://lightsail.aws.amazon.com/ls/remote/yourzone/instances/instancename/terminal?protocol=ssh

  2. nano ~/.ssh/authorized_keys

It should looks something like:

ssh-rsa AFGGS#%NzaC1yc2EFDSGgpCvpVhFyRSpfsdfjhgasdDSduD$

This means that only one key par is allowed to connect via SSH/SFTP to your Lightsail instance (voilà!).

You should add to that file the new public key bellow:

(YOUR PREVIOUS KEY)ssh-rsa AFGGS#%NzaC1yc2EFDSGgpCvpVhFyRSpfsdfjhgasdDSduD$
(ADD NEW PUBLIC KEY) ssh-rsa ASJKAKKFS#%ASDFbsdjfhJHGJvpVhFyRSpfsdfjhgasdDSduD$
  1. Restart your server and login from your local terminal:

    ssh bitnami@yourpublicip -i /Users/youruser/.ssh/yourkeyfile

With this, I could also login via SFTP in Filezilla (Mac), adding the private key in the Site Manager.

Dorcas answered 5/9, 2019 at 17:46 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.