I am trying one line setup command.

ssh -i "$(cat kushal.pub)" kushal@ec2-18-216-221-164.us-east-2.compute.amazonaws.com "mkdir -p ~/.ssh && chmod 700 && touch ~/.ssh/authorized_keys && chmod 600 cat >> ~/.ssh/authorized_keys"

Just to break this real quick I'm reading my .pub file and then while connecting, I am creating a .ssh folder with permissions 700 and inside that folder a file with permission 600 appending my public key into it.

But I get permission Denied error(public key).

Now, I did have connected instance manually by copying the public key generated by ssh-keygen -y and through a series of commands. But I don't what's going wrong with the same commands but in one line. How can I work it out?

And to overflow my question a bit more. Is there any difference if I use ssh-keygen -y compared to ssh-keygen - t rsa for generating public key files?

Just making sure if this won't make any difference to the error output

  • 1
    ssh -i expects the filename of the identity file, not the content. This should be ssh -i kushal.pub. – Gerald Schneider Jul 26 '18 at 7:33
  • Ok. I did this cause I needed to pipe the output on the server. The output in this case being content yeah...Actually I need to place my output of cat command to ssh -i command. So yes, I am doing something wrong. – kushalvm Jul 26 '18 at 7:42

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged or ask your own question.