Running a script when users connect through ssh [duplicate]

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
0
down vote

favorite













This question already has an answer here:



  • Ssh login hook?

    2 answers



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.







share|improve this question













marked as duplicate by andcoz, Jesse_b, G-Man, schily, slm♦ bash
Users with the  bash badge can single-handedly close bash questions as duplicates and reopen them as needed.

StackExchange.ready(function()
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();

);
);
);
Jul 12 at 4:35


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.














  • 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 at 16:03










  • Look at How to execute a system-wide script upon any ssh login (with OpenSSH)?
    – andcoz
    Jul 11 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 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 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 at 18:57















up vote
0
down vote

favorite













This question already has an answer here:



  • Ssh login hook?

    2 answers



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.







share|improve this question













marked as duplicate by andcoz, Jesse_b, G-Man, schily, slm♦ bash
Users with the  bash badge can single-handedly close bash questions as duplicates and reopen them as needed.

StackExchange.ready(function()
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();

);
);
);
Jul 12 at 4:35


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.














  • 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 at 16:03










  • Look at How to execute a system-wide script upon any ssh login (with OpenSSH)?
    – andcoz
    Jul 11 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 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 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 at 18:57













up vote
0
down vote

favorite









up vote
0
down vote

favorite












This question already has an answer here:



  • Ssh login hook?

    2 answers



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.







share|improve this question














This question already has an answer here:



  • Ssh login hook?

    2 answers



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.





This question already has an answer here:



  • Ssh login hook?

    2 answers









share|improve this question












share|improve this question




share|improve this question








edited Jul 11 at 19:15
























asked Jul 11 at 15:56









Pastudent

33




33




marked as duplicate by andcoz, Jesse_b, G-Man, schily, slm♦ bash
Users with the  bash badge can single-handedly close bash questions as duplicates and reopen them as needed.

StackExchange.ready(function()
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();

);
);
);
Jul 12 at 4:35


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.






marked as duplicate by andcoz, Jesse_b, G-Man, schily, slm♦ bash
Users with the  bash badge can single-handedly close bash questions as duplicates and reopen them as needed.

StackExchange.ready(function()
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();

);
);
);
Jul 12 at 4:35


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.













  • 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 at 16:03










  • Look at How to execute a system-wide script upon any ssh login (with OpenSSH)?
    – andcoz
    Jul 11 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 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 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 at 18:57

















  • 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 at 16:03










  • Look at How to execute a system-wide script upon any ssh login (with OpenSSH)?
    – andcoz
    Jul 11 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 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 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 at 18:57
















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 at 16:03




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 at 16:03












Look at How to execute a system-wide script upon any ssh login (with OpenSSH)?
– andcoz
Jul 11 at 16:08




Look at How to execute a system-wide script upon any ssh login (with OpenSSH)?
– andcoz
Jul 11 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 at 17:27




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 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 at 17:34




@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 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 at 18:57





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 at 18:57











2 Answers
2






active

oldest

votes

















up vote
0
down vote



accepted










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.





share|improve this answer






























    up vote
    0
    down vote













    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).





    share|improve this answer





















    • 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 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 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 at 19:58

















    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    0
    down vote



    accepted










    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.





    share|improve this answer



























      up vote
      0
      down vote



      accepted










      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.





      share|improve this answer

























        up vote
        0
        down vote



        accepted







        up vote
        0
        down vote



        accepted






        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.





        share|improve this answer















        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.






        share|improve this answer















        share|improve this answer



        share|improve this answer








        edited Jul 12 at 10:17


























        answered Jul 11 at 22:27









        alux

        364




        364






















            up vote
            0
            down vote













            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).





            share|improve this answer





















            • 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 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 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 at 19:58














            up vote
            0
            down vote













            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).





            share|improve this answer





















            • 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 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 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 at 19:58












            up vote
            0
            down vote










            up vote
            0
            down vote









            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).





            share|improve this answer













            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).






            share|improve this answer













            share|improve this answer



            share|improve this answer











            answered Jul 11 at 19:02









            ctrl-alt-delor

            8,64331946




            8,64331946











            • 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 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 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 at 19:58
















            • 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 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 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 at 19:58















            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 at 19:16





            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 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 at 19:56




            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 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 at 19:58




            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 at 19:58


            Popular posts from this blog

            How to check contact read email or not when send email to Individual?

            Displaying single band from multi-band raster using QGIS

            How many registers does an x86_64 CPU actually have?