메뉴 닫기

CentOS MOTD 커스터 마이징

MOTD란 message of the day라 하여 유저가 로그인시 특정 메시지를 뛰우는걸 말한다.

CentOS에서는 /etc/motd 파일에 전달할 메시지를 적어 놓는다.

네트웍크 장비 혹은 리눅스를 좀 다뤄본 사람이라면 장비에 접속시 only authorized user….
이런 형식으로 출력 되는것을 많이 보았을것이다.

보통 motd는 아래와 같이 sshd_config 파일의 옵션중 PrintMotd를 yes로 해주고 서비스 재시작후
motd 파일에 메시지를 적는다.

[root@host-192-168-0-23 ~]# cat /etc/ssh/sshd_config | grep PrintMotd
PrintMotd yes
[root@host-192-168-0-23 ~]# service sshd restart
Stopping sshd:                                             [  OK  ]
Starting sshd:                                             [  OK  ]
[root@host-192-168-0-23 ~]# cat /etc/motd
#################################################

Welcome to our server.

This is test server.

Authorized person only.

#################################################

주로 사용 용도가 경고 혹은 환영의 인사를 접속시 보여주기 위함이다.

이번에는 좀 색다르게 motd를 커스터 마이징 해서 서버 로그인시 서버 상태를 나타나게 해보도록 하겠다.

먼저 어떤 정보를 보여줄지를 결정 해보자.

모니터링의 가장 중요한 cpu와 메모리는 반듯이 포함되야 할것이이며 프로세스의 숫자와 현재 파티션
사용률 현황을 표시 하도록 하겠습니다.

먼저 /etc/ssh/sshd_config 파일의 PrintMotd 옵션을 no로 바꿔주고 서비스 재시작한다.

[root@host-192-168-0-23 ~]# cat /etc/ssh/sshd_config | grep PrintMotd
PrintMotd no

[root@host-192-168-0-23 ~]# service sshd restart
Stopping sshd:                                             [  OK  ]
Starting sshd:                                             [  OK  ]

 

그 다음 로그인시 실행할 스크립트를 /etc/profile.d/ 경로로 가서 만듭니다.

[root@host-192-168-0-23 profile.d]# cat motd.sh 
#!/bin/sh
cpu=`top -n 1 | grep -i cpu\(s\)| awk '{print $5}' | tr -d "%id," | awk '{print 100-$1}'`
memory=`free -m | awk 'NR==2{printf "%s/%sMB (%.2f%)\n", $3,$2,$3*100/$2 }'`
disk=`df -h | awk '$NF=="/"{printf "%d/%dGB (%s)\n", $3,$2,$5}'`
ps=`ps -ef |wc -l`

echo "
############################################################

Welcome to our server.

This is test server.

Authorized person only.

CPU load : $cpu %

MEMORY : $memory

DISK : $disk

PROCESS NUMBER : $ps

############################################################"

자 이제 다시 로그인할시에는 커스터 마이징한 환영인사가 출력 됩니다.

[root@host-192-168-0-23 profile.d]# logout
Connection to xxx.xxx.xxx.xxx closed.

smileserv@smileserv-desktop:~$ ssh -l root xxx.xxx.xxx.xxx -p xxxx
root@xxx.xxx.xxx.xxx's password: 
Last login: Sat Oct 10 14:21:56 2015 from xxx.xxx.xxx.xxx

############################################################

Welcome to our server.

This is test server.

Authorized person only.

CPU load : 0.6 %

MEMORY : 853/996MB (85.64%)

DISK : 2/99GB (3%)

PROCESS NUMBER : 81

############################################################
[root@host-192-168-0-23 ~]#
Subscribe
Notify of
guest
1 Comment
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
trackback

[…] 장영호 과장님 작성 – CentOS MOTD 커스터 마이징 […]

1
0
Would love your thoughts, please comment.x
()
x