在 /etc/motd 中運行腳本

在 /etc/motd 中運行腳本

我想在人們登入伺服器時運行 python 腳本。我認為編輯 /etc/motd 將是最好的方法,但由於它只是可讀文件,所以這是行不通的。

我發現幾乎相同的帖子:是否可以將指令放入 /etc/motd 中?

這裡最好的解決方案是什麼?我想運行一個顯示伺服器概述的腳本,以便用戶可以立即看到狀態。

這是建議的A useful practice is to put the command you want to be executed in a script named /etc/motd.sh and call this script from /etc/profile, usually at about the end of it.

但收到了這個評論Putting output like a MOTD in your profile is likely to break sftp.

任何解決方案都可以。先致謝

答案1

實際上,最好使用 /etc/profile.d 作為此選項。還有源腳本。它會在每次登入時顯示輸出。

關於第二個問題和breakinf sftp。我做了一點谷歌搜尋。

您可以使用:

Subsystem sftp /usr/lib/openssh/sftp-server

在 /etc/ssh/sshd_config.conf 中

或添加

if [ "$SSH_TTY" ]
then
   source .bashc_real
fi

到你的腳本列印類似 motd 的訊息。我從(使用 .bashrc 而不破壞 sftp)。

答案2

在 Ubuntu/Debian 中,PAM 模組pam_motd支援動態 motd 功能,據說它不會幹擾 sftp。不幸的是,它沒有很好的記錄。您可以改為諮詢update-motd 線上說明頁在Ubuntu中。

在 Ubuntu 系統上,您已經有多個/etc/update-motd.d/.它們是適合您自己開始的活生生的例子。

仔細考慮每次使用動態 motd 登入時消耗某些資源。讀最佳實踐update-motd 線上說明頁中的部分。

相關內容