Debian Jessie 8.2에서 ssh에 대한 오늘의 동적 메시지(motd)를 설정하는 방법은 무엇입니까?

Debian Jessie 8.2에서 ssh에 대한 오늘의 동적 메시지(motd)를 설정하는 방법은 무엇입니까?

다이나믹 모드를 하고 싶은데 어떻게 해야 할지 모르겠습니다.

내가 찾은 것을 시도하여 , /etc/update-motd.d/00-header10-sysinfo심볼릭 링크를 , 또는 90-footer에 추가 했습니다 ./etc/motd /var/run/motd.dynamic/run/motd.dynamic/run/motd/var/run/motd

나는 다음 줄을 가지고 있습니다 /etc/pam.d/sshd:

# Print the message of the day upon successful login.
# This includes a dynamically generated part from /run/motd.dynamic
# and a static (admin-editable) part from /etc/motd.
session    optional     pam_motd.so  motd=/run/motd.dynamic
session    optional     pam_motd.so noupdate

나는 또한 systemd에 대해 혼란스러워합니다.

이를 수행할 수 있는 방법이 있습니까? 누군가 간단한 부의 예를 들어줄 수 있나요?

답변1

이 상황은 수년에 걸쳐 변경되었습니다.

첫 번째는 (정적)입니다 /etc/motd.

update-motd그런 다음 Ubuntu는 cron이 호출하는 스크립트를 기반으로 자체 패키지를 제공합니다.

마지막으로 PAM은 Ubuntu의 /etc/update-motd.d/ 아이디어를 복사했기 때문에 Debian과 다른 운영 체제에도 이러한 동작이 있습니다.

여기에 설명이 있습니다

https://ownyourbits.com/2017/04/05/customize-your-motd-login-message-in-debian-and-ubuntu/

그래서 지금 일어나고 있는 일은 다음과 같습니다. PAM은 존재하는 경우에만 읽습니다 /var/run/motd.dynamic( /etc/motd게시물에서 붙여넣음).

  • /etc/motd– 클래식 정적 파일. Ubuntu 16.04 LTS에는 더 이상 존재하지 않으며 /var/run/motd에 대한 심볼릭 링크로도 존재하지 않습니다. 생성되면 해당 내용도 인쇄됩니다.
  • /var/run/motd– 이것은 Ubuntu의 첫 번째 구현에서 사용되었습니다. 더 이상 사용되지 않습니다. PAM에서는 무시됩니다.
  • /var/run/motd.dynamic– 현재 로그인 상태일 때 표시되는 내용입니다. /etc/init.d/motd에 의해 부팅할 때마다 업데이트됩니다. PAM은 /etc/update-motd.d/에 있는 스크립트를 실행하여 업데이트할 수도 있습니다.
  • /etc/motd.tail– /etc/update-motd.d를 채우는 데 사용되는 Ubuntu 패키지. 그 중 하나는 파일의 내용을 캡처하므로 정적 콘텐츠를 쉽게 추가할 수 있습니다. 스크립트가 더 이상 패키지에 존재하지 않으므로 파일이 예상한 효과를 얻지 못합니다.

게시물의 예

mkdir /etc/update-motd.d
rm -f /etc/motd                  # in Debian still exists
cat > /etc/update-motd.d/10logo <<EOF
#!/bin/sh
echo
cat /etc/issue
EOF

cat > /etc/update-motd.d/20updates <<'EOF'
#!/bin/sh
echo
echo "uptime is $( uptime )"
echo "date   is $( date   )"
EOF

chmod a+x /etc/update-motd.d/*

답변2

아래와 같이 Debian Jessie 8.2 호스트에서 Fortune 샘플을 사용하여 간단한 동적 motd를 테스트할 수 있었고 문제가 잘못된 동작과 관련되어 있음을 발견했습니다.

mkdir /etc/update-motd.d
cd /etc/update-motd.d

다음 두 개의 테스트 파일을 생성하고 실행 가능하게 만듭니다.

root@debian:/# cd /etc/update-motd.d/
root@debian:/etc/update-motd.d# ls -l 
total 8
-rwxr-xr-x 1 root root 58 Dec  1 23:21 00-header
-rwxr-xr-x 1 root root 41 Dec  1 22:52 90-fortune
root@debian:/etc/update-motd.d# cat 00-header 
#!/bin/bash
echo
echo 'Welcome !! This is a header'
echo
root@debian:/etc/update-motd.d# cat 90-fortune 
#!/bin/bash
echo
/usr/games/fortune
echo

그러나 이때 motd에는 아무런 변화가 없었다. 그래서 sshd 프로세스를 추적해봤습니다. 이 추적(아래 표시된 흥미로운 부분)에서 새로 생성된 motd.new 파일의 이름이 /var/run/motd로 변경되었음을 알 수 있습니다. 그러나 그런 다음 /run/motd.dynamic에서 읽으려고 시도하지만 생성되지 않습니다.

20318 rename("/var/run/motd.new", "/var/run/motd") = 0
20318 open("/run/motd.dynamic", O_RDONLY) = -1 ENOENT (No such file or directory)
20318 open("/etc/motd", O_RDONLY)       = 8

문제는 pam_motd 모듈의 불일치와 관련된 것으로 보입니다. 오류 보고서 보기https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=743286;msg=2

/run/motd.dynamic방금 motd 파일 위치를 변경했습니다 /run/motd. - /etc/pam.d/sshd저에게 적합하도록 만들었습니다.

root@debian:/etc/pam.d# grep pam_motd sshd
#session    optional     pam_motd.so motd=/run/motd.dynamic
session    optional     pam_motd.so motd=/run/motd
session    optional     pam_motd.so noupdate

다음은 SSH 로그인 중에 표시되는 MOTD의 예입니다.

Welcome !! This is a header


* Culus fears perl - the language with optional errors


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.
You have new mail.
Last login: Tue Dec  1 23:49:57 2015 from x.x.x.x

답변3

이 파일을 사용하여 스크립트를 실행할 수도 있습니다.

그것은 무엇을 /etc/profile위해 사용됩니까? 이 파일은 사용자 셸의 환경 항목을 설정하는 데 사용됩니다. umask와 같은 항목과 PS1 또는 PATH와 같은 변수.

그것은 무엇을 ~/.bashrc위해 사용됩니까? 이 파일은 bash 쉘 사용자가 사용하는 명령 별명 및 기능을 설정하는 데 사용됩니다.

이 파일은 언제 사용됩니까? 차이점은 간단합니다. /etc/profile대화형 쉘에서만 실행되고 ~/.bashrc대화형 쉘과 비대화형 쉘 모두에서 실행됩니다. 실제로 우분투에서는 직접 /etc/profile호출됩니다 ~/.bashrc.

(원천:https://bencane.com/2013/09/16/understanding-a-little-more-about-etcprofile-and-etcbashrc/)

관련 정보