done is better than perfect

自分が学んだことや、作成したプログラムの記事を書きます。すべての記載は他に定める場合を除き個人的なものです。

SSHでGNU/Linuxにログインした時のメッセージを変えてみた

SSHDebian GNU/LinuxなどのUNIX系OSにログインした際,以下の様なメッセージが表示されることがあります.

Linux v157-7-141-207 3.13-1-amd64 #1 SMP Debian 3.13.10-1 (2014-04-15) x86_64

The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.

このメッセージをもう少し有用な感じに変えてみました.

  • License文の削除
  • uptimeと現在ログインしているメンバーの表示
  • tmux lsの結果表示(tmuxが起動しているかどうか)

Debianzshを想定しています.

  1. License文の削除

Debianなら,以下のファイルの中身を削除します.

sudo vim /etc/motd
  1. uptimeと現在ログインしているメンバーの表示,及びtmux lsの結果表示

~/.zprofileに以下を追記します.

w
echo "" # for spacing
zmodload zsh/regex
TMUX_LS=$(tmux ls 2>&1)
if [[ $TMUX_LS -regex-match "refused$" ]]; then
    echo -e "\e[1;31m No tmux windows! \e[m"
else
    echo -e "\e[1;31m Tmux detected! \e[m"
fi

こうすることによって,以下の様な表示になります.

Linux v157-7-141-207 3.13-1-amd64 #1 SMP Debian 3.13.10-1 (2014-04-15) x86_64
No mail.
Last login: Thu Jun 12 13:49:24 2014 from 133.9.62.162
 14:29:45 up 10 days, 20:02,  2 users,  load average: 0.00, 0.01, 0.05
USER     TTY      FROM             LOGIN@   IDLE   JCPU   PCPU WHAT
******** pts/0    ************ 水19   18:18m  0.09s  0.09s -zsh
******** pts/1    ************     14:29    0.00s  0.00s  0.00s w

 No tmux windows /*実際には赤の太文字で表示

参考: * A Better Debian SSH Login Message * zshでログイン・ログアウト時に実行されるファイル