How to configure Cygwin for key-based login

0

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
/home/admin

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

Mahmoud Abd El-Fattah

Posted 2015-09-21T15:11:36.433

Reputation: 1

Answers

0

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.

Jakuje

Posted 2015-09-21T15:11:36.433

Reputation: 7 981

Should this command be executed on local machine or on the server ? – Mahmoud Abd El-Fattah – 2015-09-22T08:27:37.187

On local machine, where you have your keys – Jakuje – 2015-09-22T09:42:37.727

0

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.

rubynorails

Posted 2015-09-21T15:11:36.433

Reputation: 254

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 – 2015-10-05T14:13:38.747

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 – 2015-10-05T17:53:30.513