36

Normally, when you load a saved session in PuTTY and connect to it, PuTTY will set the window title to the host name of the system you connected to (plus the string "PuTTY").

Now I have many different sessions that all connect to the same host, but on different ports (because the host runs several SSH tunnels on different ports). Therefore seeing the host name is not very helpful, since it's always the same.

So I'd like PuTTY to show the name of the loaded session in the window title. Is there a way to do this?

The only way I could find is to set the window title manually (Window / Behaviour / Window title). But I believe I'd have to do this manually for each session, which is rather tedious.

Peter Mortensen
  • 2,319
  • 5
  • 23
  • 24
sleske
  • 9,851
  • 4
  • 33
  • 44
  • 1
    Kitty is the best telnet / SSH client (fork of Putty) and You can set window title from command line by "-title" option. – Mareg Jan 03 '19 at 19:38

9 Answers9

67

The solution below seems to solve this problem.

1) Go to the aforementioned Window/Behaviour/Window Title setting and put in a title that makes sense to you.

2) Go to the Terminal/Features settings and check off the Disable remote-controlled window title changing box.

Setting 1

Setting 2

Patrick Mevzek
  • 9,273
  • 7
  • 29
  • 42
Andy
  • 681
  • 1
  • 5
  • 3
  • 4
    While this may answer the question, it's preferable if you can summarise the answer here as links do go dead over time. – Ladadadada May 28 '14 at 10:43
  • 3
    This is the procedure described on that site: In the putty session setup window enable the checkbox labelled "Disable remote-controlled window title changing" found under Terminal->Features. Next give your session window a name via the Window->Behaviour dialog. Enter the title into the textbox labelled "Window title:" – BdN3504 Oct 14 '15 at 14:57
  • 3
    This should be the answer. +1 – Kulasangar Aug 26 '16 at 10:41
  • 7
    This should have been the accepted answer. Without this second point, my title kept resetting itself as soon as I pressed enter key. (host: Windows, remote server: Ubuntu Server 16.04 LTS) – Zeeshan Nov 09 '16 at 17:47
22

To change the PuTTY SSH session window title (one by one manually by the PuTTY GUI):

For Windows & Debian

  1. Load a session from PuTTY.
  2. On left side tree menu, click on: WindowBehaviour.
  3. On the right panel, in the Window title text box enter your title.
  4. Save the session.

To change the PuTTY SSH session window title (for all sessions by command line):

For Debian 8 (Jessie)

  1. Go to the folder where PuTTY stores sessions: /home/nolwennig/.putty/sessions

    Note: replace nolwennig with your username

  2. Assign to parameter WinTitle the saved session file name for each saved session file with something like this:

    find . -type f -exec sed -e 's/^WinTitle=/WinTitle=%f/g' {} \;

    It works fine if no WinTitle is recorded

For Windows

  1. PuTTY stores sessions in Windows registry HKEY_CURRENT_USER\Software\Simontatham\PuTTY\Sessions

    Note: not replace SimonTatham with your username.

  2. You can export this section with a command like this:

    C:> regedit /e "%userprofile%\desktop\putty-registry-sessions.reg" HKEY_CURRENT_USER\Software\Simontatham\PuTTY\Sessions
    
  3. It must be possible to make a script that updates the putty-registry-sessions.reg file to change the value of WinTitle for each of the saved sessions.


Sources & inspirations:

Peter Mortensen
  • 2,319
  • 5
  • 23
  • 24
Nolwennig
  • 340
  • 3
  • 8
  • I know I can do that - it's mentioned in my question, along with why I am looking for a different solution. – sleske Dec 31 '15 at 13:34
  • I update my answer with a little script – Nolwennig Jan 04 '16 at 14:09
  • 1
    Neat idea with the script. However, AFAIK, Putty by default stores sessions in the Windows registry. If yours uses files, you are probably using a modified version (though it might still work by exporting/importing the config). Could you mention that in the answer? – sleske Jan 04 '16 at 14:25
  • I'm on Debian8 here, I add the location of Putty sessions storage for Windows in my answer but I can't write/test a script for that now : ( – Nolwennig Jan 04 '16 at 15:54
  • 1
    Oh, right, forgot that PuTTY has a Linux version, too. Anyway, nice answer, thanks. – sleske Jan 05 '16 at 10:30
19

This function will set the title of your PuTTY window to the given string:

# Set title
title() {
  echo -ne "\033]0;"$1"\007"
}

You can use this to set the title from the command line or from scripts, e.g. from within .bashrc.

Peter Mortensen
  • 2,319
  • 5
  • 23
  • 24
Thomas Stuefe
  • 291
  • 2
  • 3
  • 1
    Why does this work? – Chad May 31 '16 at 22:07
  • 1
    Just a little note; You still have to set `"Disable remote-controlled window title changing"` under `Terminal->Features` – 244an Oct 22 '16 at 05:40
  • You may want to use `printf` command instead. – MUY Belgium Feb 14 '17 at 13:28
  • Why does this work? : `ESC ] 0 ; txt ST` Set icon name and window title to txt. – Koshinae Sep 06 '19 at 08:56
  • Why does this work? The putty window watches the output from the shell for certain combinations of control characters. One such combination is '''Ctrl-ESC ] 0 ; Ctrl-G''' - it asks the window to set the title to . – Ben Aveling Apr 30 '21 at 05:35
  • @224an - are you sure? For me, this only works if "Disable remote-controlled window title changing" is not set. (And if PROMPT_COMMAND is cleared) – Ben Aveling Apr 30 '21 at 05:48
3

I was looking for how to make window titles stick when using PuTTY with session files.

So in .putty/sessions/ServerX, set a default title and no remote behaviour as:

NoRemoteWinTitle=1
WinTitle=Welcome to ServerX

And to give it a special title for some particular purpose, just override the default:

putty -load .putty/sessions/ServerX -title "ServerX:/var/log/messages"
Peter Mortensen
  • 2,319
  • 5
  • 23
  • 24
DCG
  • 31
  • 1
2

The only other route I'm aware of is to use the xterm emulation features to set the title from the system you are logged into (on Red Hat Linux and SUSE Linux, the Bash prompt is written to the titlebar by default).

See this page for a description of the process and the relevant escape sequence.

Peter Mortensen
  • 2,319
  • 5
  • 23
  • 24
symcbean
  • 19,931
  • 1
  • 29
  • 49
0

This is how you can set a custom window title in a command line script, no WinRegistry changes or pre-defined sessions required, script must use -t -m options to run a remote commands and stay in a bash shell without an automatic exit.

Script is using a \033]0;... window title remote command escape syntax.

PuttyTestNode1.bat

set name=TestNode1
set destip=11.22.33.44
set workdir=/usr/share/nginx/www
echo echo -ne "\033]0;"%name% %destip%"\007" > tempcmd.txt
echo cd "%workdir%" >> tempcmd.txt
echo /bin/bash >> tempcmd.txt
start "putty" c:\putty\putty.exe -pw "keyfilepwd" myuser@%destip% -i myprivkey.ppk -t -m tempcmd.txt
Whome
  • 101
  • 2
0

You can use the -loghost "title" option in Windows - it opens PuTTY with the specified title name. It also changes other stuff, so please check if that's not making any other problem for you.

I'm using it with VIRL, and it works perfectly fine.

Peter Mortensen
  • 2,319
  • 5
  • 23
  • 24
0

In Windows, this will set the window title of every session to the very same name of the session:

FOR /F "tokens=6 delims=\" %i IN ('reg query HKCU\Software\Simontatham\PuTTY\Sessions') DO reg add HKCU\Software\Simontatham\PuTTY\Sessions\%i /t REG_SZ /v WinTitle /d %i /f & reg add HKCU\Software\Simontatham\PuTTY\Sessions\%i /t REG_DWORD /v NoRemoteWinTitle /d 1 /f
Peter Mortensen
  • 2,319
  • 5
  • 23
  • 24
-2

In Windows, this cmd line will set the window title of every session to the very same name of the session itself:

FOR /F "tokens=6 delims=\" %i IN ('reg query HKCU\Software\Simontatham\PuTTY\Sessions') DO reg add HKCU\Software\Simontatham\PuTTY\Sessions\%i /t REG_SZ /v WinTitle /d %i /f & reg add HKCU\Software\Simontatham\PuTTY\Sessions\%i /t REG_DWORD /v NoRemoteWinTitle /d 1 /f