Saving Your Putty Sessions To A Log File

Putty is a widely used, free, tool to SSH/Telnet/Console/etc into a network device. I can’t recall how many times I’ve burned myself because I fat-fingered the keyboard and then lost my connection to the network device or misconfigured an interface and not realize it for a couple of days. Or what if you wanted to remember what you did a couple of months ago on a switch?

Putty allows you to log each of your sessions. It has saved my bacon so many times.

Here’s how to configure it. First, highlight the Default Settings:

Putty's Default Settings

Then on the left pane, click on Logging under Session.

Under the Session Logging section, select “All session output”
For the log file name, use this structure: &H-&Y&M&D-&T.log

&H – This will append the hostname of the device to the front of the file. I add a dash after this to separate it from the dates.

&Y&M&D – This adds the year, month, and day. Add a dash afterwards to separate it from the time.

&T – This adds the time you logged into the device. Because you may log into the same device multiple times per day, this is a good way to log each session separately.

Click on browse to save it to a specific location. Your log file will then look like:


Configuring session logging in Putty

Now go back to the Session window, click on Default Settings, and click Save. So next time you open Putty or create a new saved session, it will create the log file.

Let’s see it in action. I’m going to create a new saved session for the ATT Looking Glass route server:

Creating a Saved Session in Putty

Let’s take a look at Google’s BGP routes

Image of Google's BGP Routes

Example Putty Log

Here is the contents of that log:

=~=~=~=~=~=~=~=~=~=~=~= PuTTY log 2013.10.24 07:58:42 =~=~=~=~=~=~=~=~=~=~=~=
-------------- route-server.ip.att.net ---------------
---------  AT&T IP Services Route Monitor  -----------

The information available through route-server.ip.att.net is offered
by AT&T's Internet engineering organization to the Internet community.

This router maintains eBGP peerings with customer-facing routers
throughout the AT&T IP Services Backbone:

IPv4:  Atlanta Austin  Cambridge   Chicago  Dallas Detroit  Denver Houston  LA   New York  Orlando Philly Phoenix SanDiego  SanFran  St.Louis Seattle   WashDC

2001:1890:FF:FFFF:12:122:124:12   Atlanta
2001:1890:FF:FFFF:12:122:127:66   Chicago
2001:1890:FF:FFFF:12:122:124:138  Dallas
2001:1890:FF:FFFF:12:122:120:7    Fort Lauderdale
2001:1890:FF:FFFF:12:122:125:6    Los Angeles
2001:1890:FF:FFFF:12:122:125:44   New York
2001:1890:FF:FFFF:12:122:125:106  Philadelphia
2001:1890:FF:FFFF:12:122:125:132  Phoenix
2001:1890:FF:FFFF:12:122:126:232  San Francisco
2001:1890:FF:FFFF:12:122:125:224  Seattle
2001:1890:FF:FFFF:12:122:126:9    St. Louis
2001:1890:FF:FFFF:12:122:126:64   Washington

*** Please Note:
Ping and traceroute delay figures measured here are unreliable, due to the
high CPU load experienced when complicated show commands are running.

For questions about this route-server, send email to: jayb@att.com

*** Log in with username 'rviews', password 'rviews' *** 

route-server.ip.att.net (ttyp5)

login: rviews

--- JUNOS 12.1R3-S4 built 2013-03-24 11:22:31 UTC 
rviews@route-server.ip.att.net> show route www.google.com 

inet.0: 462505 destinations, 6937311 routes (462505 active, 0 holddown, 0 hidden)
+ = Active Route, - = Last Active, * = Both    *[BGP/170] 3w2d 17:29:34, localpref 100, from
                      AS path: 7018 15169 I
                    > to via em0.0
                    [BGP/170] 2w3d 09:11:13, localpref 100, from
                      AS path: 7018 15169 I
                    > to via em0.0
                    [BGP/170] 7w5d 19:42:12, localpref 100, from
                      AS path: 7018 15169 I
                    > to via em0.0
                    [BGP/170] 7w5d 19:42:22, localpref 100, from
                      AS path: 7018 15169 I
                    > to via em0.0
                    [BGP/170] 2w0d 04:42:59, localpref 100, from
                      AS path: 7018 15169 I
                    > to via em0.0
                    [BGP/170] 7w5d 19:42:13, localpref 100, from
                      AS path: 7018 15169 I
                    > to via em0.0

rviews@route-server.ip.att.net> exit

From the text above, you can actually see my input. You won’t be able to see the passwords but you can see every other command that is typed in by me.

Note: For your previously created sessions, you will have to select it, then click Load, and modify the Logging settings to create a log for those sessions.

One thought on “Saving Your Putty Sessions To A Log File”

  1. Chompunut says:

    Good article and it is working after follow your step.

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

[gravityforms id=16 title=false description=false]
<script type="text/javascript">var gform;gform||(document.addEventListener("gform_main_scripts_loaded",function(){gform.scriptsLoaded=!0}),window.addEventListener("DOMContentLoaded",function(){gform.domLoaded=!0}),gform={domLoaded:!1,scriptsLoaded:!1,initializeOnLoaded:function(o){gform.domLoaded&&gform.scriptsLoaded?o():!gform.domLoaded&&gform.scriptsLoaded?window.addEventListener("DOMContentLoaded",o):document.addEventListener("gform_main_scripts_loaded",o)},hooks:{action:{},filter:{}},addAction:function(o,n,r,t){gform.addHook("action",o,n,r,t)},addFilter:function(o,n,r,t){gform.addHook("filter",o,n,r,t)},doAction:function(o){gform.doHook("action",o,arguments)},applyFilters:function(o){return gform.doHook("filter",o,arguments)},removeAction:function(o,n){gform.removeHook("action",o,n)},removeFilter:function(o,n,r){gform.removeHook("filter",o,n,r)},addHook:function(o,n,r,t,i){null==gform.hooks[o][n]&&(gform.hooks[o][n]=[]);var e=gform.hooks[o][n];null==i&&(i=n+"_"+e.length),gform.hooks[o][n].push({tag:i,callable:r,priority:t=null==t?10:t})},doHook:function(n,o,r){var t;if(r=Array.prototype.slice.call(r,1),null!=gform.hooks[n][o]&&((o=gform.hooks[n][o]).sort(function(o,n){return o.priority-n.priority}),o.forEach(function(o){"function"!=typeof(t=o.callable)&&(t=window[t]),"action"==n?t.apply(null,r):r[0]=t.apply(null,r)})),"filter"==n)return r[0]},removeHook:function(o,n,t,i){var r;null!=gform.hooks[o][n]&&(r=(r=gform.hooks[o][n]).filter(function(o,n,r){return!!(null!=i&&i!=o.tag||null!=t&&t!=o.priority)}),gform.hooks[o][n]=r)}});</script> <div class='gf_browser_unknown gform_wrapper gravity-theme' id='gform_wrapper_16' ><form method='post' enctype='multipart/form-data' id='gform_16' action='/saving-your-putty-sessions-to-a-log-file/' > <div class='gform_body gform-body'><div id='gform_fields_16' class='gform_fields top_label form_sublabel_below description_below'><fieldset id="field_16_1" class="gfield gfield_contains_required field_sublabel_below field_description_below gfield_visibility_visible" data-js-reload="field_16_1"><legend class='gfield_label gfield_label_before_complex' >Name<span class="gfield_required"><span class="gfield_required gfield_required_text">(Required)</span></span></legend><div class='ginput_complex ginput_container no_prefix has_first_name no_middle_name no_last_name no_suffix gf_name_has_1 ginput_container_name' id='input_16_1'> <span id='input_16_1_3_container' class='name_first' > <input type='text' name='input_1.3' id='input_16_1_3' value='' aria-required='true' placeholder='First Name' /> <label for='input_16_1_3' >First</label> </span> </div></fieldset><div id="field_16_2" class="gfield gfield--width-full gfield_contains_required field_sublabel_below field_description_below gfield_visibility_visible" data-js-reload="field_16_2"><label class='gfield_label' for='input_16_2' >Email<span class="gfield_required"><span class="gfield_required gfield_required_text">(Required)</span></span></label><div class='ginput_container ginput_container_email'> <input name='input_2' id='input_16_2' type='text' value='' class='large' placeholder='Business email address' aria-required="true" aria-invalid="false" /> </div></div><fieldset id="field_16_3" class="gfield gfield_contains_required field_sublabel_below field_description_below gfield_visibility_visible" data-js-reload="field_16_3"><legend class='gfield_label gfield_label_before_complex' >Consent<span class="gfield_required"><span class="gfield_required gfield_required_text">(Required)</span></span></legend><div class='ginput_container ginput_container_checkbox'><div class='gfield_checkbox' id='input_16_3'><div class='gchoice gchoice_16_3_1'> <input class='gfield-choice-input' name='input_3.1' type='checkbox' value='I consent to the processing and sharing with partners of the personal data that I provide Packet 6 for this activity in accordance with and as described in the &lt;a href=&quot;https://packet6.com/privacy-policy&quot; target=&quot;_new&quot;&gt;Privacy Policy&lt;/a&gt;' id='choice_16_3_1' /> <label for='choice_16_3_1' id='label_16_3_1'>I consent to the processing and sharing with partners of the personal data that I provide Packet 6 for this activity in accordance with and as described in the <a href="https://packet6.com/privacy-policy" target="_new">Privacy Policy</a></label> </div></div></div></fieldset><div id="field_16_4" class="gfield gform_validation_container field_sublabel_below field_description_below gfield_visibility_visible" data-js-reload="field_16_4"><label class='gfield_label' for='input_16_4' >Name</label><div class='ginput_container'><input name='input_4' id='input_16_4' type='text' value='' /></div><div class='gfield_description' id='gfield_description_16_4'>This field is for validation purposes and should be left unchanged.</div></div></div></div> <div class='gform_footer top_label'> <input type='submit' id='gform_submit_button_16' class='gform_button button' value='Get the report' onclick='if(window["gf_submitting_16"]){return false;} window["gf_submitting_16"]=true; ' onkeypress='if( event.keyCode == 13 ){ if(window["gf_submitting_16"]){return false;} window["gf_submitting_16"]=true; jQuery("#gform_16").trigger("submit",[true]); }' /> <input type='hidden' class='gform_hidden' name='is_submit_16' value='1' /> <input type='hidden' class='gform_hidden' name='gform_submit' value='16' /> <input type='hidden' class='gform_hidden' name='gform_unique_id' value='' /> <input type='hidden' class='gform_hidden' name='state_16' value='WyJbXSIsImY4MGVlNTA5MGVjMWYzYzU5NzUyOGFhOWE3ZGFiMzRlIl0=' /> <input type='hidden' class='gform_hidden' name='gform_target_page_number_16' id='gform_target_page_number_16' value='0' /> <input type='hidden' class='gform_hidden' name='gform_source_page_number_16' id='gform_source_page_number_16' value='1' /> <input type='hidden' name='gform_field_values' value='' /> </div> <p style="display: none !important;"><label>&#916;<textarea name="ak_hp_textarea" cols="45" rows="8" maxlength="100"></textarea></label><input type="hidden" id="ak_js_2" name="ak_js" value="94"/><script>document.getElementById( "ak_js_2" ).setAttribute( "value", ( new Date() ).getTime() );</script></p></form> </div>