Thursday, March 18, 2010

Putty, the Command Line and NO Clicky Clicky

October 5, 2009 by Greg Ferro · 28 Comments 

This Post is Part of a Series — click for list on Console Mastery»


The power of the com­mand line

I believe that you should only use the mouse when you don’t know what are doing. That is why graph­ical inter­faces exist. If you have a repet­it­ive task, then click­ing the same thing over and over shows that you are poor engin­eer. You need to take con­trol of your tools to work in the smartest way.

PuTTY is a fine example of hav­ing both options. You can clicky-​​clicky all you want and waste hours of of your life push­ing your mouse around the screen. Or you can run a lot of the repet­it­ive PuTTY actions from the com­mand line.

But first thing is to intro­duce to using the key­board to get around Windows and open the DOS box. It always sur­pris­ing how so few people know that Windows can actu­ally be driven using the key­board and very rarely need to use the mouse.

Installation

You need to note the dir­ect­ory that you installed PuTTY to, some­thing 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 cre­ate a tel­net ses­sion for a device in our net­work by enter­ing the details, enter­ing a name in the Saved Sessions box and the click­ing on the Save button

PuTTY-cli-4.jpg

Getting to grunter

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

Lot of click­ing for not much gain I would say.

Starting Windows pro­grams on the Command Line

You can start just about any pro­gram in Windows from the commad line. I am always sur­prised by how many people don’t know this. Lets look at start­ing Windows Notepad from the CLI. That is, from a DOS box, just type the com­mand “note­pad” 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 com­mand line .…

The fast­est 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 lat­er­ally, you would real­ise that the fast­est way to open Notepad would be:

  • press Command-​​Escape (together)
  • press R
  • type “note­pad”
  • and press enter
PuTTY-cli-7.jpg

Ok, now we are start­ing to get much quicker at get­ting things done.

Where’s PuTTY ?

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

PuTTY-cli-8.jpg

you will get.….

PuTTY-cli-9.jpg

It’s all about sys­tem paths

MS Windows uses a concept of paths to go search­ing for where pro­grams are loc­ated on your hard­ware. When using the DOS box, the oper­at­ing sys­tem has no con­text about where your pro­grams are loc­ated on the hard drive. When using the GUI, the inform­a­tion about where the pro­gram is loc­ated, is con­tained in the Shortcut that you are click­ing on.

You could start PuTTY by typ­ing some­thing like this:

PuTTY-cli-10.jpg

but that is too much typ­ing for me.

We can tell Windows that the dir­ect­ory where the PuTTY pro­gram is and to look in there for the pro­gram as needed.

To the Control Panel System tab then

In the Control Panel, System Properties, select the Environment Variables but­ton at the bottom:

PuTTY-cli-11.jpg

and then select Path in the System Variables sec­tion, 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 care­ful here not to delete the con­tent, if you think you have mis-​​types then just press escape and start over), on the end of the line enter the fol­low­ing text exactly (includ­ing the semi colon):
;C:\Program Files\PuTTY

PuTTY-cli-15.jpg

This set the path vari­ables to include the PuTTY pro­gram dir­ect­ory in the search path. You only have to do this once. Windows will set the the Environment Variable per­man­ently 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 con­firm the vari­ables 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 open­ing just like we were doing clicky-​​clicky all day.

PuTTY-cli-16.jpg

Ahh, the speed and the com­fort!! 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 cent­ric so there would have to be options for doing more.

Sure enough. In Section 3.8 of the Help file, clev­erly titled “The PuTTY com­mand line” we get the fol­low­ing details.

To start a con­nec­tion to a server called host:

putty.exe [-ssh | –tel­net | –rlo­gin | –raw] [user@]host

If this syn­tax is used, set­tings are taken from the Default Settings (see sec­tion 4.1.2); user over­rides these set­tings if sup­plied. Also, you can spe­cify a pro­tocol, which will over­ride the default pro­tocol (see sec­tion 3.8.3.2).

For tel­net ses­sions, the fol­low­ing altern­at­ive syn­tax is sup­por­ted (this makes PuTTY suit­able for use as a URL hand­ler for tel­net URLs in web browsers):

putty.exe telnet://host[:port]/
In order to start an exist­ing saved ses­sion called ses­sion­name, use the –load option (described in sec­tion 3.8.3.1).

putty.exe –load “ses­sion name“

ALRIGHT!!!!

Even bet­ter is this bit

3.8.3.1 –load: load a saved session

The –load option causes PuTTY to load con­fig­ur­a­tion details out of a saved ses­sion. 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 ses­sion name if it con­tains 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 con­nect­ing to equp­ment, you need to get the con­nec­tion done as fast as pos­sible. Spending all your life clicky-​​clicky on the cute little mou­sey is just dis­tract­ing you from the task at the hand. It just not geek enough, and you need to be hardcore.

This tech­nique shows a really fast way to get con­nec­ted to your devices. It works best for SSH devices although it does, kind of sup­port tel­net, just not very well.

You can now use the Windows Command Line to con­nect dir­ectly 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 learn­ing the key­board short­cuts that I talked about. Pretty quickly they will become second nature and you will have even more speed and con­fid­ence 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 favor­ite then please con­tact me using the con­tact form or put some­thing in the com­ments and I would be pleased to add it or write it up.

Please rate this post:

  Why Rate Posts?
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 ...

Comments

28 Responses to “Putty, the Command Line and NO Clicky Clicky”
  1. MCL.Nicolas says:

    Nice one greg !! It’s true some­times click­ing is just so slow ;)

  2. Patrick says:

    i use “launchy” http://​www​.launchy​.net/ for fast short­cut 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 sys­tem path attrib­utes could be changed with autoexec.bat file. So that dur­ing the boot pro­cess ini­tial­iz­a­tion 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 key­board with the Windows key. When using emu­lat­ors 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 uni­ver­sal — 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, cre­ate a short­cut on the desktop and assign a hot key to it.

        Sean

  5. Robert says:

    What´s all this enthu­si­asm about using putty ? Ok, i´ve read the art­icle:
    http://​eth​er​e​al​mind​.com/​s​e​c​u​r​e​c​r​t​-​t​o​o​-​e​x​p​e​n​s​i​v​e​-​p​u​t​t​y​-​tera-term/

    but hey, THATS the way a net­work engin­eer works: use Windows+R (or me to-​​> Launchy), type CRT and than use ALT+C or ALT+Q a lot, auto­matic login to often used ses­sions (e.g. a Jumppoint), script your login cre­den­tials -> get rid of this “no aaa author­ize exec avail­able” bull­shit in PIX/​ASA, and the list of the bene­feit over ALL other ter­minal emu­lat­ors goes on and on.

  6. Alex says:

    Well if you just use FreeBSD, Solaris, Linux or MacOS as a Desktop work­sta­tion non of this junk is neces­sary. Installing an app just to use ssh … i mean how ridicu­lous is that. Microsoft *sigh*!

    –Alex

    • Greg Ferro says:

      I’m with you, but the bulk of com­pan­ies force you to use Windows, and PuTTY is more com­mon in ser­vice pro­viders and cor­por­ates than most people ima­gine. When you dint have choices, this is best worst choice.

    • Diosbejgli says:

      ssh is also installed as an applic­a­tion on your favor­ite linux dis­tro, sup­plied in a pack­age usu­ally called openssh. the dif­fer­ence is, it’s usu­ally installed by default in most dis­tros. i think com­par­ing two OSes based on this inform­a­tion means you are ridiculous.

    • Robert says:

      yeah, and the SSH Client imple­ment­a­tion has abso­lutly NO com­fort. You can con­nect and thats it. OK, script­ing is avail­able :)

      If you´re work­ing with sev­eral con­nec­tions sim­ul­tan­eously and also want some extras, i bet that i´m ten times faster done with a good pro­gram like Secure CRT

      • Ruairi says:

        Actually, when I’m *forced* to use a win­dows box, I gen­er­ally rename putty.exe to ssh.exe, and dump it into %WINDIR%/system32 (Or the above pro­ced­ure of adding putty to your path works also). Then it’s just a quick winkey+r, fol­lowed by ssh user@host.

        Et voila!

      • Kyle says:

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

        • Greg Ferro says:

          Too expens­ive for many. Probably my favour­ite on Windows, but when you have a dozen work­sta­tions that access dif­fer­ent things, it gets very expensive.

  7. joe smith says:

    Alternatively you could use a MAC and put ter­minal in the dock, one click and you are ready to tel­net or ssh right from ter­minal. Of course you can always make that faster by using bash ali­ases 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 win­dows pop­ping up every time you want to ssh to a machine, try out mintty.

    » http://​code​.google​.com/p/mintty/ OR http://​fresh​meat​.net/​p​r​o​j​e​cts/mintty

    I no longer use cmd.exe or putty. I have a won­der­ful term that provides: “xterm-​​compatible ter­minal emu­la­tion. Its fea­tures include a simple options dia­log, Unicode sup­port, drag and drop of files and folders, and win­dow trans­par­ency.“
    Windows is usable again!

  9. Alex says:

    OMG !

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

    –Alex

  10. Will says:

    Great tutorial — 

    A much sim­pler method which I usu­ally do as a stand­ard on any Windows VM builds is copy the putty.exe execut­able into the C:\windows dir­ect­ory and rename it to “ssh.exe”. Then I hit a start-​​run — type ssh x.x.x.x and viola — I open a ssh ses­sion to the host I want. As long as the default ses­sions set­tings are set to the con­nec­tion type SSH then you are good. I usu­ally use the built in tel­net cli­ent in win­dows or SecureCRT when tel­net is needed.

  11. Robert says:

    I’m a die hard putty user but my net­work has hun­dreds of sys­tems that I have log into. Putty con­nec­tion man­ager is the way to go on this one. I cre­ated a data­base with that is laid out with folders that I can nav­ig­ate through to find the box I need to con­nect to. This is the anti­thesis of of what this art­icle is all about.

    For my quick and dirty con­nec­tion I use cyg­win ssh. Works just like the linux ver­sion. And as for my Windoze laptop, good ol’ ker­mit to the res­cue. It also does zterm trans­fers for copy­ing up IOS images, that is if you don’t have the thumb-​​drive available.

    • Greg Ferro says:

      A supris­ing num­ber of com­pan­ies do not allow you to install extra soft­ware, so I haven’t attemp­ted to cover non-​​core fea­tures of PuTTY.

  12. Victor says:

    I use port­able ver­sion of Putty and it is called Kitty
    To start it quickly I assigned key com­bin­a­tion on short­cut (Ctrl+Alt+T)

  13. Starix says:

    Just thanks for such a clear tutorial!

Speak Your Mind

Tell us what you're thinking...
and oh, if you want a pic to show with your comment, go get a gravatar!