2 September 2010

Putty, the Command Line and NO Clicky Clicky


The power of the command line

I believe that you should only use the mouse when you don’t know what are doing. That is why graphical interfaces exist. If you have a repetitive task, then clicking the same thing over and over shows that you are poor engineer. You need to take control of your tools to work in the smartest way.

PuTTY is a fine example of having both options. You can clicky-clicky all you want and waste hours of of your life pushing your mouse around the screen. Or you can run a lot of the repetitive PuTTY actions from the command line.

But first thing is to introduce to using the keyboard to get around Windows and open the DOS box. It always surprising how so few people know that Windows can actually be driven using the keyboard and very rarely need to use the mouse.

Installation

You need to note the directory that you installed PuTTY to, something like this would be the default.

PuTTY-cli-1.jpg

and now we are ready to go:

PuTTY-cli-2.jpg

Start PuTTY

So, we are ready to start PuTTY, click start, and PuTTY menu will be clearly displayed.

PuTTY-cli-3.jpg

So lets create a telnet session for a device in our network by entering the details, entering a name in the Saved Sessions box and the clicking on the Save button

PuTTY-cli-4.jpg

Getting to grunter

So normal people would click on Start, All Programs, PuTTY, PuTTY, Click grunter and the Open.

Lot of clicking for not much gain I would say.

Starting Windows programs on the Command Line

You can start just about any program in Windows from the commad line. I am always surprised by how many people don’t know this. Lets look at starting Windows Notepad from the CLI. That is, from a DOS box, just type the command “notepad” and the away it will go.

PuTTY-cli-5.jpg

None of this clicky clicky business.

But we can make this even faster.

Fastest Way to open the the command line ….

The fastest way to open the Windows Start box is to press Control-Escape which will open the Windows Start menu (as if you had clicked on the Start button).

Then press the “r” key (for Run), and type “cmd” and the Windows DOS box (or whatever you choose to call it) will open on your screen.

PuTTY-cli-6.jpg

Fastest way for Notepad would be ….

If you are thinging laterally, you would realise that the fastest way to open Notepad would be:

  • press Command-Escape (together)
  • press R
  • type “notepad”
  • and press enter
PuTTY-cli-7.jpg

Ok, now we are starting to get much quicker at getting things done.

Where’s PuTTY ?

So you might think that it would be very easy to just type PuTTY using the same technique. But alas, it does not. Give it a go and do something like this:

PuTTY-cli-8.jpg

you will get…..

PuTTY-cli-9.jpg

It’s all about system paths

MS Windows uses a concept of paths to go searching for where programs are located on your hardware. When using the DOS box, the operating system has no context about where your programs are located on the hard drive. When using the GUI, the information about where the program is located, is contained in the Shortcut that you are clicking on.

You could start PuTTY by typing something like this:

PuTTY-cli-10.jpg

but that is too much typing for me.

We can tell Windows that the directory where the PuTTY program is and to look in there for the program as needed.

To the Control Panel System tab then

In the Control Panel, System Properties, select the Environment Variables button at the bottom:

PuTTY-cli-11.jpg

and then select Path in the System Variables section, and press the Edit button.

PuTTY-cli-12.jpg
PuTTY-cli-13.jpg

and it will look like this ( you need to be a little bit careful here not to delete the content, if you think you have mis-types then just press escape and start over), on the end of the line enter the following text exactly (including the semi colon):
;C:\Program Files\PuTTY

PuTTY-cli-15.jpg

This set the path variables to include the PuTTY program directory in the search path. You only have to do this once. Windows will set the the Environment Variable permanently from now on.

You will need to logout at this point, or restart. The Path Variables are only read once at boot time.

When you come back, open the DOS box again (Ctrl-Escape, R, cmd, Enter – just to remind you), and type path to confirm the variables are in place.

PuTTY-cli-17.jpg

Alrighty then, lets try that again

Ctrl-Escape, R (for run), PuTTY

PuTTY-cli-14.jpg

and we get PuTTY opening just like we were doing clicky-clicky all day.

PuTTY-cli-16.jpg

Ahh, the speed and the comfort!! Can you feel that ?

But you’re right, I want even less clicking…..

BUT, I still have to click on grunter and then open with my mouse hand. Is strikes me that PuTTY was built by people who are really CLI centric so there would have to be options for doing more.

Sure enough. In Section 3.8 of the Help file, cleverly titled “The PuTTY command line” we get the following details.

To start a connection to a server called host:

putty.exe [-ssh | -telnet | -rlogin | -raw] [user@]host

If this syntax is used, settings are taken from the Default Settings (see section 4.1.2); user overrides these settings if supplied. Also, you can specify a protocol, which will override the default protocol (see section 3.8.3.2).

For telnet sessions, the following alternative syntax is supported (this makes PuTTY suitable for use as a URL handler for telnet URLs in web browsers):

putty.exe telnet://host[:port]/
In order to start an existing saved session called sessionname, use the -load option (described in section 3.8.3.1).

putty.exe -load “session name”

ALRIGHT!!!!

Even better is this bit

3.8.3.1 -load: load a saved session

The -load option causes PuTTY to load configuration details out of a saved session. If these details include a host name, then this option is all you need to make PuTTY start a session.

You need double quotes around the session name if it contains spaces.

So now I can open a DOS box (Ctrl-Escape, R, cmd, Enter – just to remind you again), then type:

PuTTY-cli-18.jpg

YES! Freedom from the mouse!

A little review then

If you spend all day connecting to equpment, you need to get the connection done as fast as possible. Spending all your life clicky-clicky on the cute little mousey is just distracting you from the task at the hand. It just not geek enough, and you need to be hardcore.

This technique shows a really fast way to get connected to your devices. It works best for SSH devices although it does, kind of support telnet, just not very well.

You can now use the Windows Command Line to connect directly to a SSH host by using this syntax:

putty.exe -ssh emind@198.18.14.9

or you can use telnet

putty.exe telnet://192.168.1.48/

You will need to spend some time learning the keyboard shortcuts that I talked about. Pretty quickly they will become second nature and you will have even more speed and confidence as you move around your network.

More options

This really is only just the start of what can do with PuTTY, and there are lots more things. If you have a favorite then please contact me using the contact form or put something in the comments and I would be pleased to add it or write it up.

Please rate this post:

1 Star - It\\\'s Crud2 Stars - It\\\'s Tosh3 Stars - Something\\\'s missing4 Stars - Needs works5 Stars - Good Enough6 Stars - Good7 Stars - Excellent8 Stars - Brilliant9 Stars - Astonishing10 Stars - Awesomely Godlike? (6 votes, average: 4.83 out of 10)
Loading ... Loading ...

About Greg Ferro
Greg is a Network and Security Architect / Designer / Engineer working freelance in the UK and worked for Resellers, DotCom's, Large Corporate's and Service Providers across a variety of products & Vendors. He prefers to work for end users, believes in the life cycle, total cost of ownership and that near enough is often good enough. He likes talking about himself in the first person to feel "royal", even when hosting the Packet Pushers Podcast on Data Networking. More about Greg at http://etherealmind.com/who-am-i/ and you can follow him on Twitter.

Comments

  1. MCL.Nicolas says:

    Nice one greg !! It’s true sometimes clicking is just so slow ;)

  2. Patrick says:

    i use “launchy” http://www.launchy.net/ for fast shortcut start (Putty, SAP, Outlook) etc.
    Nice, but not so nice as Quicksilver :-)

  3. shivlu jain says:

    Thank god I know all the tricks what you have told. The system path attributes could be changed with autoexec.bat file. So that during the boot process initialization occurs.

    But really its nice post.

  4. reloadin10 says:

    Even quicker then “CTRL + ESC” is “WINDOWS KEY + R”.

    I also second the use of Launchy.

    • Greg Ferro says:

      Assumes that you have a keyboard with the Windows key. When using emulators or rdp, the Windows key doesn’t always work. Since I can’t rely on it, I don’t use it.

      • Sean says:

        Start -> Run, “R” isn’t universal — other things can get in the way.

        For example, I have remote desktop pinned to my start menu, so I would need to do “Start -> Run, R, R” because the first R takes me to remote desktop.

        Alternatively, create a shortcut on the desktop and assign a hot key to it.

        Sean

  5. Robert says:

    What´s all this enthusiasm about using putty ? Ok, i´ve read the article:
    http://etherealmind.com/securecrt-too-expensive-putty-tera-term/

    but hey, THATS the way a network engineer works: use Windows+R (or me to-> Launchy), type CRT and than use ALT+C or ALT+Q a lot, automatic login to often used sessions (e.g. a Jumppoint), script your login credentials -> get rid of this “no aaa authorize exec available” bullshit in PIX/ASA, and the list of the benefeit over ALL other terminal emulators goes on and on.

  6. Alex says:

    Well if you just use FreeBSD, Solaris, Linux or MacOS as a Desktop workstation non of this junk is necessary. Installing an app just to use ssh … i mean how ridiculous is that. Microsoft *sigh*!

    -Alex

    • Greg Ferro says:

      I’m with you, but the bulk of companies force you to use Windows, and PuTTY is more common in service providers and corporates than most people imagine. When you dint have choices, this is best worst choice.

    • Diosbejgli says:

      ssh is also installed as an application on your favorite linux distro, supplied in a package usually called openssh. the difference is, it’s usually installed by default in most distros. i think comparing two OSes based on this information means you are ridiculous.

    • Robert says:

      yeah, and the SSH Client implementation has absolutly NO comfort. You can connect and thats it. OK, scripting is available :)

      If you´re working with several connections simultaneously and also want some extras, i bet that i´m ten times faster done with a good program like Secure CRT

      • Ruairi says:

        Actually, when I’m *forced* to use a windows box, I generally rename putty.exe to ssh.exe, and dump it into %WINDIR%/system32 (Or the above procedure of adding putty to your path works also). Then it’s just a quick winkey+r, followed by ssh user@host.

        Et voila!

      • Kyle says:

        Word.. Secure CRT has the best of both worlds…

  7. joe smith says:

    Alternatively you could use a MAC and put terminal in the dock, one click and you are ready to telnet or ssh right from terminal. Of course you can always make that faster by using bash aliases so you can shorten “ssh -l user my.server.com” to “my.server.com”.

  8. Elliot says:

    Hi,

    If you get fed up with putty windows popping up every time you want to ssh to a machine, try out mintty.

    >> http://code.google.com/p/mintty/ OR http://freshmeat.net/projects/mintty

    I no longer use cmd.exe or putty. I have a wonderful term that provides: “xterm-compatible terminal emulation. Its features include a simple options dialog, Unicode support, drag and drop of files and folders, and window transparency.”
    Windows is usable again!

  9. Alex says:

    OMG !

    ssh(1) + screen(1) … that’s all im going to say. i dont expect windows admins to understand.

    -Alex

  10. Will says:

    Great tutorial —

    A much simpler method which I usually do as a standard on any Windows VM builds is copy the putty.exe executable into the C:\windows directory and rename it to “ssh.exe”. Then I hit a start-run – type ssh x.x.x.x and viola — I open a ssh session to the host I want. As long as the default sessions settings are set to the connection type SSH then you are good. I usually use the built in telnet client in windows or SecureCRT when telnet is needed.

  11. Robert says:

    I’m a die hard putty user but my network has hundreds of systems that I have log into. Putty connection manager is the way to go on this one. I created a database with that is laid out with folders that I can navigate through to find the box I need to connect to. This is the antithesis of of what this article is all about.

    For my quick and dirty connection I use cygwin ssh. Works just like the linux version. And as for my Windoze laptop, good ol’ kermit to the rescue. It also does zterm transfers for copying up IOS images, that is if you don’t have the thumb-drive available.

  12. Victor says:

    I use portable version of Putty and it is called Kitty
    To start it quickly I assigned key combination on shortcut (Ctrl+Alt+T)

  13. Starix says:

    Just thanks for such a clear tutorial!

  14. Jay Paul says:

    Can PuTTY command line be used with VBScript to completely automate daily download of files?

  15. argh says:

    Man, I wish I would have realized earlier, this is kind of just a silly way of running putty.
    I expected to be able to Run putty *inside* console2 or cmd prompt.

    not all is lost however, as I did go get puTTy finally, and I happened to read the part about plink.

    plink argh@argh.org

    no one wants to use puTTy’s ugly interface do they? No WAY!!
    so I don’t look like so much of a dick, to the people seeing this in the future. oh yeah “Hi” :) <3
    I am going to tell you how to do it.

    http://sourceforge.net/projects/console/
    http://the.earth.li/~sgtatham/putty/latest/x86/plink.exe

    get a free shell account:
    http://shells.red-pill.eu/

    add, plink to path
    path C:\where-ever-you-put-plink
    plink -P 30 shellmix.com

    then you can make an account
    and log into it again on 22 by doing:

    plink yourcrazyusername@shellmix.com

    or maybe you have ssh enabled on your trusty dd-wrt:
    plink 192.168.1.1

  16. srpter says:

    You missed a lot of good flags

    -pw myPassword
    logging in right from the cmd

    putty userName@gunther -pw myPass

    or running a file of commands

    -m c:\path\to\file\of\linux\commands.txt

Speak Your Mind

*