436

Is there a way to configure a password for a stored session in PuTTY?

I know there is the capability to specify an "auto-login username" (under Connection/Data), but is there a way to do the same with the password?

jldupont
  • 6,714
  • 16
    Use KiTTy... its developed using PuTTy source code.. – user79032 Apr 13 '12 at 12:52
  • 7
    use key pairs, not passwords – ladieu Nov 21 '14 at 15:21
  • Superputty and kiTTY.exe are my choice for now. Yo can either set the password in the supperputty session with -pass in 'Extra Arguments' , or directly in the kitty/putty session in its ssh settings – Chris Sep 17 '22 at 10:44

18 Answers18

477

For some versions of PuTTY, it's as simple as one of:

putty.exe mylogin@somewhere.com -pw mypassword
putty.exe somewhere.com -l mylogin -pw mypassword

If you want to connect using SSH, use this:

putty.exe -ssh root@somewhere.com -pw mypasswordforsomewherecom

For those using Windows, you can simply create a shortcut and pass in these parameters.

For example:

  1. Create a shortcut on the desktop to putty.exe
  2. Rename the shortcut to PuTTY - server.com
  3. Right-click shortcut and choose Properties
  4. Modify the target similar to: "C:\Program Files\PuTTY\putty.exe" user@server.com -pw password
  5. Click OK

If your PuTTY does not support the pw parameter, you will need a public key as explained in:
Creating and Copying Your Key-Pair in PuTTY SSH Client (alternate up-to-date instruction source).

Jason C
  • 10,805
harrymc
  • 480,290
  • 12
  • Great tip, I now have a set of desktop links to our dev servers! Very useful. – aglassman Aug 23 '13 at 15:48
  • 2
    putty.exe -ssh @<ip/domain> -pw –  Mar 30 '14 at 07:15
  • 10
    @aglassman and others - you do of course value your servers etc security... storing passwords unencrypted is genrally not a great idea, RSA keys is the way to go. Do use it for access for things like Raspberry Pi where i don't care who uses it - thanks! – Wilf Apr 12 '14 at 10:16
  • 43
    The question wasn't whether one should or shouldn't, it was "how". – harrymc Apr 23 '14 at 15:55
  • 7
    Lol, this answer would never fly in info security... Which is exactly why it belongs on superuser :) – Sun Sep 27 '14 at 14:24
  • 6
    I really don't wanna talk down this answer, since - as harrymc said - the question was about how and not if, but just consider WHEN to use this and where rather to implement RSA keys. There are some valid places where no harm is done, going that way (and it definately is faster to set up), but just remember that one tiny vulnerabilty (tech or no-tech) on such a client, hands an attacker the server on a silver tablet (which, as mentioned above, might not be a problem in some cases though). – Levite Nov 03 '14 at 11:41
  • 1
    @harrymc - I want to take this example further. How do I also make the shortcut login to a specific folder when i click it ? If possible, how do i make it also execute clear command ? – Steam Dec 08 '14 at 21:55
  • 1
    @harrymc - I have some more questions. What if I have multiple servers (20-30) and my login changes every month or so due to security policies. How do I change the login info stored in each shortcut without repeating for each server ? Is there one place to do it ? – Steam Dec 08 '14 at 21:56
  • @Steam: You could store the shortcuts on a USB key to take with you, optionally together with a portable version of PuTTY. Security-wise, it is not a good idea to put them in a network folder. – harrymc Dec 09 '14 at 21:01
  • 1
    I did create a key pair and can now login automatically. However, I don't understand how this is more safe than the -pw option? The private key is stored on the computer, anyone with access to it can read it just like one could read the plaintext password. – jackthehipster Oct 07 '15 at 10:43
  • 1
    @jackthehipster: It's more secure since the password is not transferred in plain text over the network and cannot be sniffed. As regarding someone having access to your computer, it's only a tiny bit more secure, since it's not stored in plain text within the script/shortcut. But there is no possible security anyway in that case. – harrymc Oct 07 '15 at 11:07
  • 1
    @harrymc: Hm. But with the -ssh option, the pw would not be transferred in plain text over the net, right? So the only difference that remains would be that the key is stored in a file on the pc, while the pw is stored within the shortcut, is that right? – jackthehipster Oct 07 '15 at 12:44
  • 1
    For SSH you are usually correct. As SSH exploits do exist, the key gives a two-factor security. I would also say that the key cannot be stolen by a visitor just seeing it displayed on the screen. – harrymc Oct 07 '15 at 14:23
  • Using passwords is not safe, but sometimes unavoidable.

    I simply save the password in the saved session name, then copy it into the clipboard and paste into the shell when prompted for a password. Saves time, lowers stress and is no more insecure than keeping the password in a file. Just in case you wonder: it will be saved in the Windows registry.

    – NightKnight on Cloudinsidr.com Nov 22 '16 at 23:54
  • only second option with -l mylogin works for me on Ubuntu with Putty 0.67 – iiic Jul 24 '17 at 08:56
  • Also port can be specified by the option '-P': putty.exe -ssh user@ip -pw password -P port – محسن عباسی Jul 07 '18 at 04:02
  • "putty.exe -ssh root@somewhere.com -l yourid -pw mypasswordforsomewherecom" : works for me! – sailfish009 Oct 07 '20 at 00:13
  • For Windows I do: Step1. Create myname.bat Step 2. Edit myname.bat as example start E:\PuTTY\putty.exe root@ip_my_server -pw password -i "E:\SSH\private.ppk" -loghost "My title (remote ip)" Step 3. Doubleclick myname.bat –  Юрий Светлов Oct 20 '20 at 14:02
  • we should warn user who wants to use it, for security reason. when we apply this option on the server, we can read password from running command parameters. it is not secure. of course I know, putty have not option for store password in config. WinSCP have this ability, unfortunately WinSCP is only for transport files, not for using as a terminal. – Znik Sep 07 '22 at 12:06
118

Strongly advise using the public key mechanisms rather than sending passwords from the shell.
Here is one more reference for the setup.

Link to get latest PuTTY binaries (and check the FAQ).

nik
  • 56,306
  • 9
    +1 for the right way. Storing passwords in plaintext anywhere is a poor idea. – Zac B Dec 03 '12 at 18:45
  • 34
    @nik Don't get me wrong, You're right. But this is superuser site, if I want to auto login with password You may assume I have a good reason to do it. – matt Jan 15 '14 at 18:11
  • 1
    @ZacB - I am new to security. If an attacker has root access to your system, then can't he just log all your keystrokes, record your videos etc and get all your logins and such anyway ? Of course, plain text storage removes the need for the attacker to put all that effort, right ? – Steam Dec 08 '14 at 21:59
  • 4
    @Steam: you're right, a compromised system is a Really Bad Thing. But that's no reason not to have secondary (post-breach) threat protection. If a system is compromised at the root level, it should be as hard as possible for the attacker to compromise other parts of your infrastructure, and as likely as possible that they will be detected when doing so. Getting a keylog requires a sustained (more likely to be detected) intrusion and the installation of noticeable new software. Stealing a text file does not. – Zac B Dec 09 '14 at 13:59
  • I was on the corporate VPN when I tried to download PuTTY from that site, and I was prevented because it contained a virus! – OmarOthman Mar 20 '16 at 13:37
  • The linked guide is a bit out of date (2009) and didn't want to work for me. Here is one that worked for me in 2018. It still uses Putty/Puttygen, just with a couple details changed. – felwithe Mar 08 '18 at 01:26
  • Correct me if I'm wrong, but I think this requires Sudoer privileges on the target Linux machine/VM? If so it's not a workable solution for everyone. – KidACrimson Apr 18 '19 at 14:31
  • 2
    I am using an RSA key, not a password, but the SSH key was created in WHM and therefore required a passphrase. Turns out PuTTY accepts that passphrase using the -pw command option. So there is a secure use case for -pw after all. – David Spector Sep 27 '19 at 23:17
  • Does not address the question at all. @Zac B hopefully you have some hours in the saddle now. Keys are just longer passwords that have to be stored somewhere. If I can copy and paste 12 characters I can copy and paste 400. It is also harder to enforce change policies. – mckenzm Mar 26 '24 at 22:08
94

I use WinSCP to “auto login” in PuTTY with a password. It's free, contains plenty of features, was created in 2000 and is still activity maintained. (WinSCP Wikipedia page)

STEP 1:

  • Login to your WinSCP.
  • Select Options -> Preferences (View -> Preferences in Explorer interface). Then follow the screenshot below:

Preferences -> Integration -> Applications -> (select remember session password)

STEP 2:

  • Follow the screenshot below.

NOTE: Opening PuTTY from WinSCP can be done from either the login window, or from the SFTP window, which I find extremely handy:

Commands -> (Open in PuTTy)

Franck Dernoncourt
  • 21,280
  • 51
  • 203
  • 349
  • 2
    Ah man, why am I learning this trick after years of using both product independently! While it does not answer the question directly, it's awesome.

    I do tons of scripting at work and my flow is the following: WinSCP to open and save modifications remotely. VS Code to, hum... well code and Putty to run the script on the dev servers. I know I could do everything from VS Code, but this requires minimal configuration and everything runs as it will once in prod.

    When I have to handle temporary servers with local creds, this is going to make my life a bit simpler.

    – Prevok Feb 13 '24 at 14:41
37

If you want to preserve saved options (such as pre-configured window sizes and tunnel proxy) and load a saved session to auto-login, use this approach: http://www.shanghaiwebhosting.com/web-hosting/putty-ssh-auto-login

putty.exe -load my_server -l your_user_name -pw your_password

Where 'my_server' is a saved session name.

datasn.io
  • 525
22

PuTTY Connection Manager is a separate program that works with PuTTY. It can autologin and has an encrypted database holding the passwords.

I still prefer SSH keys though.

(Another downside is that it may no longer be supported by its original developer(s), and may only be available to download from third-party sources.)

  • 2
    If you use a passphrase for SSH keys, doesn't that make SSH keys just as hard to use as regular username and password? – Buttle Butkus Apr 30 '17 at 20:26
17

There's a port of PuTTY called KiTTY which allows saving username / password.

The kitty_portable.exe is very handy; no installation is needed.

  • 1
    Much better than storing server credentials in plain text with PuTTY. Thanks. Would be a complete answer had you mentioned how to do it with KiTTY. – pras92 Sep 07 '20 at 17:45
  • can pass user and password from data section but it doesnt remember for the next session. its not saving the data. – Feroze Mohamed Jun 13 '22 at 08:09
12

Combining two different packages for a security solution can be dangerous. This is the PuTTY-only way to do it, only using software from the PuTTY site.

You should first use PuTTYgen to create a key pair, then install the private key in PuTTY, and copy the public key to the remote site. Here is how you do this.

Download PuTTYgen, and execute it to generate a SSH2-RSA key. I'd use at least 4098 bits. Click the Generate button, move the mouse around, until the key pair is generated.

enter image description here

Once it's generated, your screen will look like this: enter image description here

Describe the account in the "Key Comment" field. Then save the private key in one file, and the public key in another file.

Your public key will look like this:

---- BEGIN SSH2 PUBLIC KEY ----
Comment: "rsa-key-20160822"
AAAAB3NzaC1yc2EAAAABJQAAAgEA5Kp+G9z8eE0MpPZL9JZksstIa3L9JEND6ud1
1IiD6f1jw/7Lv7CvZcCdk/OVMT+DlTbryRoqfbNMLkjajqNTUGBAscTduUtPYuQt
YEQgtbJd/hyHtTHK9X/wiKeQr7LjHZcEg3osYh+MzZFscldQM/a/Z26AKh81EC9X
uIu98snjOBM0ysb14Uu7hMvti5Xd3kSW7ctL2j1ORuRgZX6LHihaezvsBFI5S/lZ
4v/yxymRKQnyV6OkMNMXESJpXh3cTMIIGtDJtbbYvh5Qs0f3O1fMiQYyz2MjGphd
zBihq85a1SHx0LBk31342HsCiM4el//Zkicmjmy0qYGShmzh1kfZBKiBs+xN4tBE
yjRNYhuMGP2zgpr9P/FO1buYdLah5ab3rubB5VbbRP9qmaP2cesJS/N91luc099g
Z+CgeBVIiRr1EYTE8TqsSBdvmu3zCuQgDVcSAoubfxjM4sm3Lb6i4k4DJmF57J6T
rcyrSIP9H/PDuBuYoOfSBKies6bJTHi9zW2/upHqNlqa2+PNY64hbq2uSQoKZl1S
xwSCvpbsYj5bGPQUGs+6AHkm9DALrXD8TX/ivQ+IsWEV3wnXeA4I1xfnodfXdhwn
ybcAlqNrE/wKb3/wGWdf3d8cu+mJrJiP1JitBbd4dzYM0bS42UVfexWwQSegDHaw
Aby0MW0=
---- END SSH2 PUBLIC KEY ----

You have to edit this to a form that is suitable for your remote site. Let's assume it's a Linux machine using ssh.

Edit the file so it has three fields:

  1. The first should say "ssh-rsa"
  2. The second should be your public key all on one line with no spaces.
  3. The third is a comment - which can correspond to your key comment field.

So it should look like this when done

ssh-rsa AAAAB3NzaC1yc2EAAAABJQAAAgEA5Kp+G9z8eE0MpPZL9JZksstIa3L9JEND6ud11IiD6f1jw/7Lv7CvZcCdkOVMT+DlTbryRoqfbNMLkjajqNTUGBAscTduUtPYuQtYEQgtbJdhyHtTHK9XwiKeQr7LjHZcEg3osYh+MzZFscldQMaZ26AKh81EC9XuIu98snjOBM0ysb14Uu7hMvti5Xd3kSW7ctL2j1ORuRgZX6LHihaezvsBFI5SlZ4vyxymRKQnyV6OkMNMXESJpXh3cTMIIGtDJtbbYvh5Qs0f3O1fMiQYyz2MjGphdzBihq85a1SHx0LBk31342HsCiM4elZkicmjmy0qYGShmzh1kfZBKiBs+xN4tBEyjRNYhuMGP2zgpr9PFO1buYdLah5ab3rubB5VbbRP9qmaP2cesJSN91luc099gZ+CgeBVIiRr1EYTE8TqsSBdvmu3zCuQgDVcSAoubfxjM4sm3Lb6i4k4DJmF57J6TrcyrSIP9HPDuBuYoOfSBKies6bJTHi9zW2upHqNlqa2+PNY64hbq2uSQoKZl1SxwSCvpbsYj5bGPQUGs+6AHkm9DALrXD8TXivQ+IsWEV3wnXeA4I1xfnodfXdhwnybcAlqNrEwKb3wGWdf3d8cu+mJrJiP1JitBbd4dzYM0bS42UVfexWwQSegDHawAby0MW0= rsa-key-20160822

Personally, I would copy the file over to the Linux machine, and then edit it, because editors like vim are much more tolerant of long lines. I'd use the 'J' command to join two lines, then search for spaces and delete the spaces between the lines. When I copied this file over to Windows, the system insisted on splitting the single long line into multiple lines with "\" between the lines. Yuck. To continue...

Log into the remote machine, and copy/edit, then append the public key into the ~/.ssh/authorized_keys file in the same format as the other keys. It should be a single line. There should be three fields on a single line. The first says "ssh-rsa". The second is the key which should end with the characters "=" the third field is optional, and will contain what you put in the Key Comment field.

If this is the first time you have created the ~/.ssh/authorized_keys file, make sure the directory and file are not group or world readable.

Once this is done, then you have to create a PuTTY session where the private key is used.

In the PuTTY session, go to Connection=>SSH=>Auth and click browse and select where you stored your private key "It's a *.ppk" file. enter image description here

Then save this session (I'm assuming you also set up the account, IP address, etc.).

Once this is done, you just have to select the session, and you are logged in.

A more secure way is to store your private key in an encrypted file, using a passphrase. Then use Pageant to manage your passphrase. That way the private key is always encrypted, and you only have to type in a passphrase once in a while.

  • With these detailed instructions, it's not hard to get going. With Pageant, you're completely secure and I only have to type my password once for all my keys on startup. – Noumenon Aug 29 '18 at 15:06
12

I use mRemote on Windows; it can store usernames and passwords for SSH, RDP, VNC and Citrix.

Gareth
  • 18,809
Dentrasi
  • 11,205
  • I found this pretty buggy on Win7. Dragging the window around caused major hangs. Shame because apart from that it is great. – jsims281 Jan 11 '12 at 16:51
10

Yes, there is a way. Recently I added a password saving feature for PuTTY 1.5.4 for both Linux and Windows. You can download binaries and source from Oohtj: PuTTY 0.62 with a password saving feature.

oohtj
  • 101
  • 1
  • 2
9

Tunnelier - saved passwords encrypted locally. It also has a sFTP GUI as well as SSH windows.

enter image description here

Diogo
  • 30,480
9

If the connection is authenticated by a public key and password, consider using Pageant which is part of the PuTTY suite.

You can add your private keys to Pageant with the associated password. Assuming you've got the correct username configured in PuTTY, you will be authenticated transparently.

It doesn't store your keys/passwords long-term so you'll have to re-add next time you launch it. There is a command line option to launch and add keys in one go.

"C:\Program Files\PuTTY\Pageant.exe" key1.ppk key2.ppk key3.ppk

It will prompt for a password if required.

And best of all, it's part of the PuTTY suite, so you've probably already got it on your machine.

Basic
  • 1,095
  • 1
    this answer should receive more upvotes. It's the only way, if we're using SSH public key authentication, instead of username/password. – tinker Aug 26 '20 at 09:51
8

If you use the following way, don't forget to add "" to enclose your session name, or it may fail to load the session. For example,

putty.exe -load "my session name", 

The general form is:

putty.exe -load my_server -l your_user_name -pw your_password
holly
  • 181
6

I prefer doing like this on a Windows machine. Save the PuTTY executable in a folder, say "mytools", and run this command from command prompt:

tools>mytools 10 

10 is the last octet of your IP address. That's it.

@ECHO OFF
set PUTTY=E:\tools\putty.exe
start %PUTTY% root@192.168.1. %1 -pw yourpassword
oorda
  • 61
  • Perfect. But by doing this, all of color customizations are gone and I am stuck with native PuTTy ugly color-scheme. I have added these reg files http://www.igvita.com/2008/04/14/custom-putty-color-themes/ as my color scheme but can i use it somehow ? – Em Ae Feb 21 '13 at 17:57
  • Yes, in two ways: 1. In PuTTY, make all your color customizations on the session called "Default Settings" which is the first one in the list. 2. Use the -load cli option in your putty shortcut, e.g.: start %PUTTY% -load "myCustomColorSession" -l yourusername -pw yourpassword – Amit Naidu May 20 '20 at 03:22
4

I would like to explain more on Emrald214s answer on MTPutty as its a nice free software.

MTPutty - Multi-tabbed putty (portable version because of corporate installation limitations for many users) as it helps to connect to many servers and its easy to organize in folders with this free software.

  1. you can save your username password in session setting itself enter image description here
  2. you can fire automated commands after logging from script tab of new connection. this is very helpful if you need to set some scripts (specially alias scripts) on startup of your session. also you can automate logging of sesu but its not recommended as the password will be in plain text e.g. enter image description here

in above script SLEEP is for wait in between commands in miliseconds. Alternatively for default wait time you can specify "wait period before typing commands" in script window instead of _SLEEP command

Note:

  1. MTPutty is just an interface hence you will also need to download kitty or putty to use with it.
  2. The script will only work if the password is saved (otherwise it will try to take password from script :P which will result in failed login)
  3. It has export and import sessions option as well along with many other useful features.

This software helps a lot in daily operation if you need to deal with many servers.

1

Install MTPuTTY and your problem should be solved. You can even execute a bunch of scripts after logging into Putty.

1

If the command history is a security concern, go the public key route (as your plaintext password specified in the -pw option is stored in the command history).

ives
  • 499
0

If you work under windows you can create a .bat file with a text editor then put

putty.exe -ssh user@Ip_Address -pw password
0

mRemoteNG allow you to save username and password in its connection, or username in putty connections. I prefer it because it's multitab and open source.