I have successfully installed Cygwin on my 2012 server.

Now, I want to enable key-based login.

I have searched a lot for this ( I'm not a linux guru ) and everything I have found orbits around adding the key to /.ssh/authorized_keys file.

The problem is that I can't find the .ssh folder to create the file and add the key to it.

Some posts suggested to check if home variable is defined or not by executing

echo $HOME

command and see if it will output anything or not.

The outpu was

$ echo $HOME

I already have the key generated from the client machine. I just want to know where to put it.

I have found this question but I couldn't get the exact steps from it.

Thank you


The easiest way is to run ssh-copy-id user@host, which will copy your public keys to correct location on host.

Copying it by hand causes frequently access rights issues.

| improve this answer | |
  • Should this command be executed on local machine or on the server ? – Mahmoud Abd El-Fattah Sep 22 '15 at 8:27
  • On local machine, where you have your keys – Jakuje Sep 22 '15 at 9:42

For those without "ssh-copy-id" installed, or those who are temporarily-unable to install it for whatever reason, the following Bash one-liner is always a valid substitute:

$ PUB="$(cat ~/.ssh/id_rsa.pub)"; ssh user@host "mkdir -p ~/.ssh; echo $PUB >> ~/.ssh/authorized_keys; chmod 700 ~/.ssh; chmod 600 ~/.ssh/authorized_keys"

The tilde-slash (~/) on the remote host probably isn't needed, but I include it just in case, in order to avoid any weird and/or unforeseen scenarios.

| improve this answer | |
  • Thanks @rubynorails and sorry for being late, I was away for some time. Should I run this command on Cygwin terminal on the client or on my windows server ? – Mahmoud Abd El-Fattah Oct 5 '15 at 14:13
  • This whole thing relies on the fact that you have ssh installed on both machines, with sshd listening on the remote host on the standard port 22 (unless otherwise configured in your local ssh_config. If you are trying to setup authentication from local-to-remote, you will execute this command on the local host, and replace user@host with [your remote username]@[remote host/ip]. I hope this helps. – rubynorails Oct 5 '15 at 17:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.