I'd like to prompt a user for some piece of information before they get to their BASH shell when they're logging in via SSH. Ideally, I'd like to execute a script which prompts them for information, check that the information is correct, and then if it is drop them to a shell. So, think:
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:
#
Can anyone provide an example of how to do something like this?
Create new login script(/bin/bash_rest):
and set as login shell:
Assuming for a moment that you're using opensshd, one possible alternative that does almost what you want, and is a lot simpler to implement, would be to use a login banner. This will not do exactly what you want it to do - it will display a text before the user logs in.
You can alter your policy accordingly - "by logging in you are accepting these terms and conditions".
You can do this using the "Banner" option in /etc/sshd/sshd_config. For example:
I would add some rudimentary logging to that bash script, and instead of making that script the default shell, I would consider /etc/ssh/sshrc or /etc/profile.local or /etc/profile. Testing is necessary, because behavior on different systems may vary. There are some reasons not to create non-standard shells, one of which is the need to add new shell to /etc/shells. Unless absolutely necessary, remain with shells defined in /etc/shells.