更改putty连接ubuntu时标题显示

最近使用多个ubuntu虚拟机,使用putty远程登陆时,标题显示的都是一致的用户名@主机名,导致不好识别连接的是哪台机器。

在网上搜了个解决办法:
在HOME目录下,修改.bashrc文件,在最后新加(注意除第一行和最后一行外,需要加TAB):
# Auto add env parameter $PROMPT_COMMAND when use non-Linux tty login by ssh.
if [ "$SSH_CONNECTION" != '' -a "$TERM" != 'linux' ]; then
declare -a HOSTIP
HOSTIP=`echo $SSH_CONNECTION |awk '{print $3}'`
export PROMPT_COMMAND='echo -ne "\033]0;${USER}@$HOSTIP:[${HOSTNAME%%.*}]:${PWD/#$HOME/~} \007"'
fi

保存后,再重新打开putty,发现没有生效。发现是ubuntu某些默认的设置跟新的设置冲突了,同样是修改HOME目录下的.bashrc文件,注释掉下面两个地方:
注释1:
# set a fancy prompt (non-color, unless we know we "want" color)
#case "$TERM" in
  xterm-color|*-256color) color_prompt=yes;;
#esac
注释2:
# If this is an xterm set the title to user@host:dir
#case "$TERM" in
#xterm*|rxvt*)
  PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h: \w\a\]$PS1"
  ;;
#*)
  ;;
#esac

保存后,重新用putty连接,putty的标题改成用户名@IP地址了。

感谢链接:
https://www.docin.com/p-1553643584.html
https://blog.csdn.net/chunran/article/details/84758223

posted @ 2020-12-15 15:53  strongbug1  阅读(87)  评论(0编辑  收藏  举报