我想在用户login到服务器时运行一个python脚本。 我认为编辑/ etc / motd将是最好的方法,但由于它只是可读文件,所以不起作用。
我发现几乎完全相同的post: 是否可以把命令放在/ etc / motd中?
这里最好的解决scheme是什么? 我想运行一个脚本来显示服务器的概述,所以用户会立即看到状态。
build议这样做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.
任何解决scheme都可以。 提前致谢
其实最好使用/etc/profile.d这个选项。 源代码在那里。 它会显示每个login输出。
关于第二个问题和breakinf sftp。 我做了一些Googlesearch。
您可以使用:
Subsystem sftp /usr/lib/openssh/sftp-server
在/ etc / ssh / sshd_config中。
或添加
if [ "$SSH_TTY" ] then source .bashc_real fi
打印出类似motd的信息。 我得到这个答案( 使用.bashrc没有打破sftp )。
在Ubuntu / Debian中,PAM模块pam_motd支持dynamicmotdfunction,据说它不会影响sftp。 不幸的是它没有很好的logging。 你可以参考Ubuntu中的update-motd手册页 。
在Ubuntu系统上,在/etc/update-motd.d/已经有了几个脚本。 他们是适合你自己的现场实例。
仔细考虑使用dynamicmotd消耗每个login的某些资源。 请阅读update-motd手册页中的“ 最佳实践”部分。