PuTTY HOWTO setup Auto SSH Login or Auto SCP

Assumption: the SSH user id is "gtay", SSH Server is "ssh_server"
Objectives: we wish to "auto-login" to a SSH Server or "auto-ftp" download files from a SSH Server.

Step 1) Generate local PC private (.ppk) and public (.pub) keys

C:\PuTTY>puttygen

Click "SSH-2 (RSA)" or "SSH-2 (DSA)" depending on your choice, "SSH-1 (RSA)" is not so recommended.
Click "Generate", follow instructions to randomly move the mouse
Enter "gtay@gtay_pc BatchMode Key" into "Key Comment" field or any text that is meaningful to describe the key as the default text is not so meaningful.

Leave blank (NULL) to passphrase field(s)
Save public key as "gtay@gtay_pc.pub"
Save private key as "gtay@gtay_pc.ppk", click "Yes" to confirm to save without passphrase
Select and copy (Ctrl-C) the text under the section "Public key for pasting into OpenSSH authorized_keys file:" into clipborad, it is something like:

ssh-rsa AAAAB3NzaC1yc2EAAAABJQAAAIB314mo2tZt61OsO2lRmWLLhILKQ0g2tVHBomnwfkeceHNw3FJLQ1awtMztk56gUiZtt/wIFh++hCAHfOZrZx0rDXEsr+ZxqX8SKHt+qyGi68vtLMZ3WfsmZxB3VEFPdp9MoXKLGpu2kWuLiZUYibxKawtYp4Cpn3mbJojgYTljZQ== gtay@gtay_pc BatchMode Key

Close Window to exit.

Under the "Putty Configuration" of PuTTY,
Enter all needed details for a typical PuTTY session, like hostname/IP,...
Set Connection/Data/Auto-login name to "gtay",
Set Connection/SSH/Preferred SSH protocol version to "2",
Set Connection/SSH/Auth/Private key file for authentication to "C:\PuTTY\gtay@gtay_pc.ppk",
Save the PuTTY session, I suggest you save it as "gtay@ssh_server" to make it more meaningful.

Step 2) Append the content of local PC OpenSSH formatted public key to the Remote OpenSSH Server $HOME/.ssh/authorized_key.

At the local PC, take a look at both the public key and private key, note that the public key is similar to the format required by OpenSSH but not quite the same, i.e. there is additional "ssh-rsa" at the beginning and the comment field is at the end.

C:\PuTTY>type gtay@gtay_pc.pub
---- BEGIN SSH2 PUBLIC KEY ----
Comment: "gtay@gtay_pc BatchMode Key"
AAAAB3NzaC1yc2EAAAABJQAAAIB314mo2tZt61OsO2lRmWLLhILKQ0g2tVHBomnw
fkeceHNw3FJLQ1awtMztk56gUiZtt/wIFh++hCAHfOZrZx0rDXEsr+ZxqX8SKHt+
qyGi68vtLMZ3WfsmZxB3VEFPdp9MoXKLGpu2kWuLiZUYibxKawtYp4Cpn3mbJojg
YTljZQ==
---- END SSH2 PUBLIC KEY ----

C:\PuTTY>type gtay@gtay_pc.ppk
PuTTY-User-Key-File-2: ssh-rsa
Encryption: none
Comment: gtay@gtay_pc BatchMode Key
Public-Lines: 4
AAAAB3NzaC1yc2EAAAABJQAAAIB314mo2tZt61OsO2lRmWLLhILKQ0g2tVHBomnw
fkeceHNw3FJLQ1awtMztk56gUiZtt/wIFh++hCAHfOZrZx0rDXEsr+ZxqX8SKHt+
qyGi68vtLMZ3WfsmZxB3VEFPdp9MoXKLGpu2kWuLiZUYibxKawtYp4Cpn3mbJojg
YTljZQ==
Private-Lines: 8
AAAAgFD5atnf+Ksids5RqAazv0s929TFrVVlwZ6Cfu6ag2m5K2fuz9H9EQ+cwdD1
ClCmNaQUh7Jv0EJ08wv6cizkzoPx0ncu4LM6BtBU9ds3y2XBY5nMuzipS+OzDh6Q
fqrcL/u0KH1dEUUfW5I6e6rWmh1IN54Xww4NxoN45qqgRY3JAAAAQQDAcsK97Tvs
IRAiZ5t1X7wSt6zFJKjpX4KecoDb2uhrclhIE6SACb2Yr7hOOuhJVCPFoDhvJgyF
rwJxQgfcKkw3AAAAQQCfasPLUH5nfOIsLSPjLnk1vkhNHBQuXoX9Di+ijDb4f4oR
S++gMLuhXUJ+ZbiH6nYwTAMK8kCfAPTZYhlu5ZdDAAAAQQCy9xnDaqV/Prj3UrpR
LfBhusaRwVh2x+GysH3Gjk6wDTaLtwZxmqG84LhQjtxiIYRFW86w0o3nITyU1tvK
qpQZ
Private-MAC: 272608024cefa99fba135f30bcdc8bfe71df82d4

Login as "gtay" into the OpenSSH Server

login as: gtay
gtay@192.168.1.168's password:
Last login: Fri Aug 26 03:49:27 2005 from 192.168.1.188
bash-2.05$ pwd
/home/gtay
bash-2.05$ cd .ssh
bash-2.05$ vi authorized_keys

Paste the content you saved for the OpenSSH formatted public key from the clipboard into authorized_keys, if there exists this file and some entries, do not overwrite them, append the content to the end.

ssh-rsa AAAAB3NzaC1yc2EAAAABJQAAAIB314mo2tZt61OsO2lRmWLLhILKQ0g2tVHBomnwfkeceHNw3FJLQ1awtMztk56gUiZtt/wIFh++hCAHfOZrZx0rDXEsr+ZxqX8SKHt+qyGi68vtLMZ3WfsmZxB3VEFPdp9MoXKLGpu2kWuLiZUYibxKawtYp4Cpn3mbJojgYTljZQ== gtay@gtay_pc BatchMode Key

 

Login as "root" into the OpenSSH Server and perform a TRICK to avoid "sftp-server: not found" error.
(Note: I choose /usr/bin as this is always in the $PATH Search Path)

# cd /usr/bin
# ln -s /usr/lib/openssh/sftp-server sftp-server

IMPORTANT: Make sure /usr/lib/openssh/sftp-server exists and is referenced in /etc/ssh/sshd_config

Step 3) Example Usages

3.1) Auto-Login

Just "Load and Open" the "gtay@ssh_server" PuTTY session file hard coded with SSH id "gtay".

Using username "gtay".
Authenticating with public key "gtay@gtay_pc BatchMode Key"
Last login: Fri Aug 26 03:49:27 2005 from 192.168.1.188
Sun Microsystems Inc.   SunOS 5.9       Generic May 2002
gtay@ssh_server:/home/gtay>

After that you could simply click "Duplicate Session" to acquire more AUTO login sessions

3.2) Using SFTP (Secure FTP) to batch download /etc/hosts from ssh_server

Type "psftp -?" for command syntax

C:\PuTTY>type testget.bc
get /etc/hosts test.txt
quit

C:\PuTTY>psftp -v -1 -batch -b testget.bc -i gtay@gtay_pc.ppk gtay@ssh_server
...
Remote working directory is /home/gtay
remote:/etc/hosts => local:test.txt
Sent EOF message
Server sent command exit status 0
Server closed network connection

3.3) Using SCP (Secure COPY) to batch upload readme.txt to /var/tmp at ssh_server

Type "pscp -?" for command syntax

C:\PuTTY>pscp -v -1 -batch -scp -i gtay@gtay_pc.ppk readme.txt gtay@ssh_server:/var/tmp
….
Sending file readme.txt, size=1285
readme.txt                |          1 kB |   1.3 kB/s | ETA: 00:00:00 | 100%
Sent EOF message
Server sent command exit status 0
Server closed network connection

Hope you enjoy the productivity gained in using this HOW-TO.