我想提醒用户在通过SSHlogin时到达BASH shell的某些信息。 理想情况下,我想执行一个脚本,提示他们提供信息,检查信息是否正确,然后是否将它们放到shell中。 所以,想想:
ssh [email protected] password: xxxx do you agree to the terms and conditions of use? enter yes or no: yes OK, here's your shell: #
任何人都可以提供一个如何做这样的事情的例子吗?
创build新的login脚本(/ bin / bash_rest):
#!/bin/bash echo "do you agree to the terms and conditions of use? enter yes or no:" read ans case $ans in y|yes|Y|Yes) bash;; *) exit esac
并设置为loginshell:
chmod +x /bin/bash_rest usermod -s /bin/bash_rest ooshro ooshro@ooshro:~$ ssh -p 2022 localhost Linux ubuntu-1010-server-01 2.6.35-25-generic-pae #44-Ubuntu SMP Fri Jan 21 19:01:46 UTC 2011 i686 GNU/Linux Ubuntu 10.10 Welcome to Ubuntu! * Documentation: https://help.ubuntu.com/ Last login: Thu Feb 24 17:43:06 2011 from 10.0.2.2 do you agree to the terms and conditions of use? enter yes or no: yes ooshro@ubuntu-1010-server-01:~$ exit Connection to localhost closed. ooshro@ooshro:~$ ssh -p 2022 localhost Linux ubuntu-1010-server-01 2.6.35-25-generic-pae #44-Ubuntu SMP Fri Jan 21 19:01:46 UTC 2011 i686 GNU/Linux Ubuntu 10.10 Welcome to Ubuntu! * Documentation: https://help.ubuntu.com/ Last login: Thu Feb 24 17:43:17 2011 from 10.0.2.2 do you agree to the terms and conditions of use? enter yes or no: no Connection to localhost closed.
假设你正在使用opensshd,一个可能的select几乎是你想要的,并且实现起来要简单得多,那就是使用login标志。 这不会做你想做的事情 – 它会在用户login前显示一个文本。
您可以相应地更改您的政策 – “通过login您正在接受这些条款和条件”。
您可以使用/ etc / sshd / sshd_config中的“Banner”选项来执行此操作。 例如:
#echo“Banner / etc / sshd / sshd-banner”>> / etc / sshd / sshd_config #回声“通过login您接受的条款和条件。” > / etc / sshd / ssh-banner
我会添加一些基本的日志logging到该bash脚本,而不是使该脚本为默认shell,我会考虑/ etc / ssh / sshrc或/etc/profile.local或/ etc / profile。 testing是必要的,因为不同系统的行为可能会有所不同。 有一些原因不能创build非标准的shell,其中之一是需要添加新的shell到/ etc / shells。 除非绝对必要,否则使用/ etc / shells中定义的shell。