14

I am trying to use ssh/scp from Windows to Linux without having to enter a password.

This is what I have done, and it doesn't seem to work:

  • generated public and private keys using Putty Key Generator (on Windows)
  • saved the files as id_rsa.pub and id_rsa
  • copied them into ~/.ssh
  • added id_rsa.pub to the Linux box in ~/.ssh/authorized_keys
  • I then try to ssh to the Linux box from Windows and I still have to enter a password

Am I missing something?

10

You have to run an authentication agent on Windows.

For example, Pageant, used in combination with PuTTY (graphical SSH client) or Plink (its command line equivalent).

You'll need to tell Pageant your SSH server's public key. After that it will deal with your server's authentication requests while running in the background.

| improve this answer | |
  • 2
    Note: (This wasn't obvious to me.) When opening Pageant, it will open as an icon in the notification area in the bottom right. Right click it, and click Add Key, and select the .ppk file that was generated from puttygen. – badjr Jan 19 '18 at 15:09
10

You need Pageant.

See the video Password-less login with PuTTY and Pageant. And/or the blog post Howto: Passwordless SSH authentication with PuTTY.

| improve this answer | |
  • 2
    Please try to link to text-based tutorials instead of videos. – a coder Mar 30 '15 at 18:43
  • The blog link is broken. Try this one: tecmint.com/ssh-passwordless-login-with-putty – Kai Wang Dec 15 '15 at 14:14
  • 2
    The blog link broken is the exact reason answers should be more then a link. – Ramhound Jul 11 '16 at 21:45
  • 1
    The blog link is not broken, at least not anymore... – Eduardo Jun 5 at 12:50
5

Try Plink (part of PuTTY)

 plink -v youruser@yourhost.com -pw yourpw "some linux command"
| improve this answer | |
  • 3
    +1 for a correct response, but you're better off using a public/private key pair than a password. – Ted Percival Jan 13 '10 at 17:09
  • Despite the alternative, with plink you can't have a normal terminal with it, for example: the arrow keys wont work for the bash history – PYK Feb 25 at 1:20
4

I used this:

c:\> type c:\users\my_name\.ssh\id_rsa.pub | ssh root@172.110.1.171 "cat >> ~/.ssh/authorized_keys"

| improve this answer | |
3

Setting up SSH key authentication can be a bit tricky. It sounds like you're covering all your bases. One thing that often catches people off guard - you need to make sure the .ssh directory and its contents are owned by you and are read/writeably only by you.

Make sure to run this (on all your .ssh directories):

chmod -R 700 on ~/.ssh

If that doesn't work, turn on verbose logging by adding -v to your ssh command (you can add up to three -vss for more verbosity).

| improve this answer | |
2

I'm assuming your keys are not password protected, and what you're getting is not a request for your key's password.

~/.ssh isn't used by putty on the windows side, and putty doesn't have a default private key setting. If you're using a command line ssh client such as cygwin, creating a .ssh directory off of your home would work. From putty, you'll need to configure and save a session.

From the putty configuration dialog, look at connection -> data, and fill in the auto-login username field. Then go to connection -> ssh -> auth, and set your private key correctly. Then go back to the session dialog, and save this session. You can also set the hostname if you'd like.

Once you have a saved session, you can use 'putty -load "savedsession"'.

| improve this answer | |
  • Also, chmod 700 ~/.ssh on the target machine, and chmod 644 ~/.ssh/authorized keys. Once I followed your instructions and set the permissions correctly, it started working for me. – Blisterpeanuts Sep 28 '18 at 15:40
1

You may also need to change permissions on your home directory:

chmod 755 ~
| improve this answer | |
1

I was able to do this exactly from Windows 7 by using the -i option for supplying an identity private key:

ssh -i X:\win-path\to\private-key remoteuser@remote.host.com

except that on the remote host, my authorized keys are in /etc/ssh/authorized_keys/remoteuser and in /etc/ssh/sshd_config, I changed

#AuthorizedKeysFile     .ssh/authorized_keys
AuthorizedKeysFile      /etc/ssh/authorized_keys/%u

but I don't know if the SSH remote config should matter.

| improve this answer | |
1

All you need is the cross-platform ssh commandline tools, ssh-keygen & ssh-copy-id. git for Windows includes them.

Either do this from the git-installed bash shell:

#By default this puts keyfile pair in ~/.ssh/id_rsa & ~/.ssh/id_rsa.pub :

ssh-keygen.exe -t rsa -b 2048 
ssh-copy-id -i ~/.ssh/id_rsa.pub  $remoteuser@$remotehost

# These two chmod lines are needed on unix platforms, probably not on Windows. 
# typically ssh refuses to use a private key file 
# if it is less-well protected than this:
chmod 700 ~/.ssh
chmod 640 ~/.ssh/id_rsa

Or run this script in PowerShell:

Param(
  [Parameter()][string]$keyfile="id_rsa",
  [Parameter()][string]$remotehost,
  [Parameter()][string]$remoteuser
  )
write-host "# ---------------------------------------------------------------------------------#"
write-host "# Create an RSA public/private key pair, and copy the public key to remote server  #"
write-host "#                                                                                  #"
write-host "# https://superuser.com/questions/96051                                            #"
write-host "#         ssh-from-windows-to-linux-without-entering-a-password/1194805#1194805    #"
write-host "#                                                                                  #"
write-host "# ---------------------------------------------------------------------------------#"

write-host "Keyfile pair will be saved at : ~/.ssh/$keyfile, ~/.ssh/$keyfile.pub"
write-host "And copied to $remoteuser@$remotehost"
write-host ""
write-host "You will need a password for the copy operation."
write-host ""

if( -not $(ls ~/.ssh) ) { mkdir ~/.ssh }
$sshdir=$(get-item ~/.ssh/).Fullname

#By default this puts keyfile pair in ~/.ssh/id_rsa & ~/.ssh/id_rsa.pub :
ssh-keygen.exe -t rsa -b 2048 -f "$sshdir$keyfile"

# ssh-copy-id somehow didn't work in Powershell so I called it via bash
bash -c "ssh-copy-id -i ~/.ssh/$keyfile.pub $remoteuser@$remotehost"

# I'm not sure if these two chmod lines work on windows but 
# typically ssh refuses to use a private key file 
# if it is less-well protected than this:
chmod.exe 700 $sshdir
chmod.exe 640 "$sshdir$keyfile"

After this, passwordless login should work for both ssh and scp.

| improve this answer | |

Your Answer

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