Posts Tagged ‘Putty’

Fix Your Linux Terminal Line Wrap Issues

I had a strange problem with Putty when connecting to a Linux server that I work on from time to time. Randomly, the command I was in the middle of typing would wrap around on itself on the same line, overwriting what I had already typed. Aside from being generally annoying, it caused plenty of headaches when trying to issue longer commands.

The problem would always when entering long commands, but it would also sometimes cause the text to wrap after only 20 or so characters. I figured something had to be wrong, and sure enough after a bit of reading, I found the culprit.

It seems that at some point I read a tutorial about how to customize the command prompt that offered tips on how to dynamically change the Putty window title as well. That’s all fine and dandy, but the author left out a very important point; How to escape non-printing characters. You see, the problem with my command prompt was that several non-printing characters were being entered on the line as part of the prompt, and the shell could not accurately determine where to wrap the line, when to add a new line, etc.

Here was my existing prompt:

PS1="[\W]\$ \e]2;[\d \t]  [\w]\a"

What this does, according to the author, is create a prompt containing the relative path of the directory I am working in (the \W) surrounded by square brackets, and ending with a “$” sign. The path looks like this:
[www]$ if I happen to be working in a directory named www – simple enough.

The second half of the command (the \e]2;[\d \t] [\w]\a) causes the date and time to be displayed in square brackets ([\d \t]) followed by the full path that I am working on ([\w]). The “\e]2;” and the “\a” are just commands that specify the fact that I wanted to change the window title rather than the command prompt.

The problem arises because even though the commands to change the window prompt are considered non-printing characters, the server would “display” them anyways, taking up room on my command line without my knowledge. The simple fix is to surround the second portion of my prompt command with a pair of brackets used for specifying non-printing characters. They are “\[" and "\]“, used to denote the beginning and end of the non-printing characters, respectively.

So, my new command looks like so:

PS1="[\W]\$ \[\e]2;[\d \t]  [\w]\a\]"

Pretty subtle change, but it makes a world of difference.

So, if you are seeing some weird behavior when connected to a Linux box with Putty or any terminal client for that matter, take a closer look at your command prompt. Added tweaks such as the window title changes I made along with any sort of color changes you might have made to your prompt are likely the culprit.

Securing Windows Remote Desktop with CopSSH

Download This Guide in PDF Format

I like having the ability to remotely access my PC at home while I am away in case I want to grab an important file I have left there, or if I need to finish something I didn’t quite get around to.  For ages I simply set port forwarding on my router allowing port 3389 to be directed to my desktop PC, which let me connect to my computer using Microsoft Remote Desktop Protocol (RDP).  While this was not the most secure method of doing so, it worked, and I did not want to change how I did things.

That’s not to say that RDP is not secure – it does use 128 bit RC4 according to Microsoft.  However, with man-in-the-middle attacks being relatively easy to carry out, I thought there had to be a better (and more secure) way of connecting to my oh so precious home network.

In the end, I decided that I could route my RDP sessions through an SSH tunnel and sleep a little easier at night.  If you follow the directions below, you can too.

Going forward in this document, I will use the term “Server” to refer to the remote computer (in my case, my home PC) that we will be connecting to.  I will use the term “Client” to refer to my local computer, the computer I will be connecting from.

Installing CopSSH

1) Download CopSSH, Putty and Puttygen.

2) Execute the CopSSH installer, click Next to proceed, then click I agree to accept the license agreement.

CopSSH Screen 1

Continue reading “Securing Windows Remote Desktop with CopSSH” »