Skip to content
Advertisement

Unable to ssh to remote server

I’m trying to log in to a particular user on my lightsail account via ssh but I get a permission denied (public key) error

Here are the steps I followed(I am on git bash on windows 8)

  1. ssh into my lightsail account via the .pem key provided via aws

    ssh -i <key.pem> ubuntu@<public_ip_address>

(I am now logged in to my lightsail server)

  1. sudo adduser user1
  2. sudo touch /etc/sudoers.d/user1
  3. sudo nano /etc/sudoers.d/user1

** user1 ALL=(ALL:ALL) ALL**

  1. su - user1

  2. sudo mkdir .ssh

  3. sudo touch .ssh/authorized_keys

I open Another shell prompt and do the following

ssh-keygen

cat <file_location_of_key>.pub

-copy the contents

  1. paste the contents of the public key created on my local machine via ssh-keygen
  2. sudo chmod 700 .ssh
  3. sudo chmod 600 .ssh/authorized_keys
  4. sudo service ssh restart
  5. exit

I exit from the lightsail account and try to ssh to the grader user

ssh -i <file_location_of_key> user1@<public_ip_address>

I get the error Permission denied (publickey).

Note: I havn’t changed any port setting yet. I’m still trying to connect it to my default port 22

Advertisement

Answer

@RickBaker @helloV Thanks for your help. Realised the file was still owned by root. Had to change to ownership of the file to user1. ssh works fine now

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement