Reputation: 1284
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)
.
Upvotes: 17
Views: 13904
Reputation: 326
To use your existing ~/.ssh/id_rsa.pub
nano ~/.ssh/authorized_keys
xclip -sel clip < ~/.ssh/id_rsa.pub
~/.ssh/authorized_keys
with the copied keyssh ubuntu@[instance_public_ip]
Upvotes: 13
Reputation: 1149
To be able to connect to your amazon lightsail instance you need to download the key first.
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.)
Save it in a folder in your local machine. For Example- "Desktop > keys"
Open the terminal and navigate to the directory where the key is stored(cd desktop/keys
)
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
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 IPYou can find your IP and username on your instance page (https://lightsail.aws.amazon.com/ls/webapp/home/instances > Select Instance> Manage)
Upvotes: 7
Reputation: 303
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:
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
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$
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.
Upvotes: 3
Reputation: 1284
LightsailDefaultPrivateKey-us-west-2.pem
chmod 600 [fileName]
at the command line to restrict file permission so only you can read itssh -i [fileName] [username]@[Public IP]
to establish the connection to Lightsail
Upvotes: 42