0

I am installing a server; I am preparing it for SSH traffic.
I would like a script to be run (a dialog with the freshly connected user) every time a user from a certain group connects.
How do I do this (kind of like in the SSH hook post)?

I want a certain a group, which i will just call users, who just want to launch a game server or something like that, to be able to do so with minimal headache. And my idea is to make a script, which launches everytime they connect, that takes their hand and allows them to execute different actions, all centered around that game server thing. I don't want admins to be bothered every time by that script.

Pastudent
  • 103
  • 1
  • 4
  • Do you want it run, however they login (ssh, or local). This is the easier solution. Or only when they login via `ssh`. This is a little bit harder, but not too hard. – ctrl-alt-delor Jul 11 '18 at 16:03
  • Look at [How to execute a system-wide script upon any ssh login (with OpenSSH)?](https://serverfault.com/questions/153445/how-to-execute-a-system-wide-script-upon-any-ssh-login-with-openssh) – andcoz Jul 11 '18 at 16:08
  • Well, i would like it to be executed, whenever a user of a certain group logs in :) (added that to main message) but apart from that it is a duplicate indeed... – Pastudent Jul 11 '18 at 17:27
  • @ctrl-alt-delor Since i want it run for only i certain group of users, i do not care whether it is local or not. Whatever is easier ! – Pastudent Jul 11 '18 at 17:34
  • You say, you want an interactive dialogue with the user, when they log in (so computer will ask question). Is this correct? What happens next, do they get a bash prompt? – ctrl-alt-delor Jul 11 '18 at 18:57
  • I am worried that the question is too abstract. Can you add to the bottom, some background. What are you trying to achieve (a non-technical explanation, that your users, and my mum, would understand). This may help us to see what type of solution will be best for you (as I said, there is more than one way to do this). – ctrl-alt-delor Jul 11 '18 at 19:05

2 Answers2

0

Some Options:

  • Change each users login shell, to be the interactive script.
  • Edit/copy each users .profile, this is run each time that bash is started when it stops the user gets their prompt.
  • Edit users ~/.ssh/authorized_keys, so to tell ssh to run a special command when user connects. This is like option 1, but for ssh only. It can also be used to allow many people with different keys to log into same account, but have different action (user separation, by action).
ctrl-alt-delor
  • 27,473
  • 9
  • 58
  • 102
  • The thing is that there could be more than 100 guys :/ I guess i could switch to keys, but i still want a good portion of the users to have their own accounts (all spawning them to the same Folder) – Pastudent Jul 11 '18 at 19:16
  • I am worried that the question is too abstract. Can you add to the bottom, some background. What are you trying to achieve (a non-technical explanation, that your users, and my mum, would understand). This may help us to see what type of solution will be best for you (as I said, there is more than one way to do this). – ctrl-alt-delor Jul 11 '18 at 19:56
  • Well, i have edited my message to explicitely say how why i need this and how i want it. Was that not enough ? – Pastudent Jul 11 '18 at 19:58
0

Why not with the /etc/profile file on the server, with one condition?

For example: Only for the group player, the script /etc/profile-grp/player is executed (sourced from /etc/profile) . It writes the date in a log file (~/log) of the user's directory.

grp=player

# Write a script
sudo mkdir /etc/profile-grp
echo "date >> ~/log" | sudo tee /etc/profile-grp/${grp}

# Script permissions
sudo chown root:${grp} /etc/profile-grp/${grp}
sudo chmod 640 /etc/profile-grp/${grp}

# In /etc/profile
echo " 
if ( groups | grep ${grp} > /dev/null); then
   . /etc/profile-grp/${grp}
fi" | sudo tee -a /etc/profile

unset grp
  • Only the player group (and root) can read the script.
  • Free to edit the script. Only root can change it.
alux
  • 36
  • 4