How would I have a script which opens a tmux session and then changes to different user without password...

Crossing US/Canada Border for less than 24 hours

In musical terms, what properties are varied by the human voice to produce different words / syllables?

Why are my pictures showing a dark band on one edge?

Has negative voting ever been officially implemented in elections, or seriously proposed, or even studied?

Project Euler #1 in C++

Drawing spherical mirrors

How to report t statistic from R

What does Turing mean by this statement?

Strange behavior of Object.defineProperty() in JavaScript

How to compare two different files line by line in unix?

What initially awakened the Balrog?

Why is it faster to reheat something than it is to cook it?

How did Fremen produce and carry enough thumpers to use Sandworms as de facto Ubers?

Converted a Scalar function to a TVF function for parallel execution-Still running in Serial mode

Conditions when a permutation matrix is symmetric

How can I prevent/balance waiting and turtling as a response to cooldown mechanics

Why weren't discrete x86 CPUs ever used in game hardware?

Amount of permutations on an NxNxN Rubik's Cube

What are the discoveries that have been possible with the rejection of positivism?

If Windows 7 doesn't support WSL, then what is "Subsystem for UNIX-based Applications"?

What's the difference between the capability remove_users and delete_users?

macOS: Name for app shortcut screen found by pinching with thumb and three fingers

How to write capital alpha?

One-one communication



How would I have a script which opens a tmux session and then changes to different user without password prompt?



Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern)
2019 Community Moderator Election Results
Why I closed the “Why is Kali so hard” questionIs there a tmux equivalent of “screen -D -R”tmux: shared session, one user in a pane, another in another pane, two different cursorsCreating MySQL database and user without passwordRun server program and allow user to attach to it using SSHTmux: resize in detach mode result in strange panes' sizeHow do run my script inside tmux on server startupCan attaching to tmux sessions be password protected, similar to gnu screen?Have tmux not ask for sudo password for a process in session (authenticate beforehand)?tmux change default working directory of a session without attachingTmux - Open a new session in another terminal window without blocking the calling terminal





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}







0















I am trying to create a script that opens a new tmux session, then changes user and runs a script inside that tmux session.



The purpose of this is to create a new tmux session for a game server, which has a different unix user assigned to it. I have heard that giving servers their own users was good practice, but I would still like to have a script in the home directory of my main user to start the server for convenience. I would like the tmux session to be available from my main user, yet be logged in to the game server user.



The main problem is that there is a password prompt that I cannot get around, requiring me to attach to the tmux session, enter the password, and then detach.
This is what I have tried:



#!/bin/sh

tmux new -d -s Minecraft sudo -u minecraft /home/minecraft/server/start.sh


I have tried every combination of running the script with sudo, adding su - Minecraft to the script, and su Minecraft -c "script", and in each one it either requires me to attach to the tmux session and login or just does not work, leaving no tmux session open.



I am trying to find a solution which would allow me to type in my sudo password or the other user's password when I run the script which invokes tmux, instead of having to login by attaching and then detaching.



Any tips would be appreciated. This is obviously a hobby project and not of vital importance. I am also new to linux and am trying to learn best practices. I am open to being told if I am taking the the wrong approach.










share|improve this question







New contributor




cory171185 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.



























    0















    I am trying to create a script that opens a new tmux session, then changes user and runs a script inside that tmux session.



    The purpose of this is to create a new tmux session for a game server, which has a different unix user assigned to it. I have heard that giving servers their own users was good practice, but I would still like to have a script in the home directory of my main user to start the server for convenience. I would like the tmux session to be available from my main user, yet be logged in to the game server user.



    The main problem is that there is a password prompt that I cannot get around, requiring me to attach to the tmux session, enter the password, and then detach.
    This is what I have tried:



    #!/bin/sh

    tmux new -d -s Minecraft sudo -u minecraft /home/minecraft/server/start.sh


    I have tried every combination of running the script with sudo, adding su - Minecraft to the script, and su Minecraft -c "script", and in each one it either requires me to attach to the tmux session and login or just does not work, leaving no tmux session open.



    I am trying to find a solution which would allow me to type in my sudo password or the other user's password when I run the script which invokes tmux, instead of having to login by attaching and then detaching.



    Any tips would be appreciated. This is obviously a hobby project and not of vital importance. I am also new to linux and am trying to learn best practices. I am open to being told if I am taking the the wrong approach.










    share|improve this question







    New contributor




    cory171185 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.























      0












      0








      0








      I am trying to create a script that opens a new tmux session, then changes user and runs a script inside that tmux session.



      The purpose of this is to create a new tmux session for a game server, which has a different unix user assigned to it. I have heard that giving servers their own users was good practice, but I would still like to have a script in the home directory of my main user to start the server for convenience. I would like the tmux session to be available from my main user, yet be logged in to the game server user.



      The main problem is that there is a password prompt that I cannot get around, requiring me to attach to the tmux session, enter the password, and then detach.
      This is what I have tried:



      #!/bin/sh

      tmux new -d -s Minecraft sudo -u minecraft /home/minecraft/server/start.sh


      I have tried every combination of running the script with sudo, adding su - Minecraft to the script, and su Minecraft -c "script", and in each one it either requires me to attach to the tmux session and login or just does not work, leaving no tmux session open.



      I am trying to find a solution which would allow me to type in my sudo password or the other user's password when I run the script which invokes tmux, instead of having to login by attaching and then detaching.



      Any tips would be appreciated. This is obviously a hobby project and not of vital importance. I am also new to linux and am trying to learn best practices. I am open to being told if I am taking the the wrong approach.










      share|improve this question







      New contributor




      cory171185 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.












      I am trying to create a script that opens a new tmux session, then changes user and runs a script inside that tmux session.



      The purpose of this is to create a new tmux session for a game server, which has a different unix user assigned to it. I have heard that giving servers their own users was good practice, but I would still like to have a script in the home directory of my main user to start the server for convenience. I would like the tmux session to be available from my main user, yet be logged in to the game server user.



      The main problem is that there is a password prompt that I cannot get around, requiring me to attach to the tmux session, enter the password, and then detach.
      This is what I have tried:



      #!/bin/sh

      tmux new -d -s Minecraft sudo -u minecraft /home/minecraft/server/start.sh


      I have tried every combination of running the script with sudo, adding su - Minecraft to the script, and su Minecraft -c "script", and in each one it either requires me to attach to the tmux session and login or just does not work, leaving no tmux session open.



      I am trying to find a solution which would allow me to type in my sudo password or the other user's password when I run the script which invokes tmux, instead of having to login by attaching and then detaching.



      Any tips would be appreciated. This is obviously a hobby project and not of vital importance. I am also new to linux and am trying to learn best practices. I am open to being told if I am taking the the wrong approach.







      shell-script sudo users tmux su






      share|improve this question







      New contributor




      cory171185 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.











      share|improve this question







      New contributor




      cory171185 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      share|improve this question




      share|improve this question






      New contributor




      cory171185 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      asked 1 hour ago









      cory171185cory171185

      1




      1




      New contributor




      cory171185 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.





      New contributor





      cory171185 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






      cory171185 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






















          1 Answer
          1






          active

          oldest

          votes


















          0














          Two approaches:




          1. Edit /etc/sudoers to allow your user to do sudo -u minecraft,
            or specifically sudo -u minecraft /home/minecraft/server/start.sh,
            without a password.

          2. Do sudo -u minecraft sleep 0 in your script before the tmux command. 
            This will ask you for your password. 
            Subsequent sudo commands for the next few minutes
            will not require a password.






          share|improve this answer
























            Your Answer








            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "106"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: false,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: null,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });






            cory171185 is a new contributor. Be nice, and check out our Code of Conduct.










            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f513503%2fhow-would-i-have-a-script-which-opens-a-tmux-session-and-then-changes-to-differe%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            Two approaches:




            1. Edit /etc/sudoers to allow your user to do sudo -u minecraft,
              or specifically sudo -u minecraft /home/minecraft/server/start.sh,
              without a password.

            2. Do sudo -u minecraft sleep 0 in your script before the tmux command. 
              This will ask you for your password. 
              Subsequent sudo commands for the next few minutes
              will not require a password.






            share|improve this answer




























              0














              Two approaches:




              1. Edit /etc/sudoers to allow your user to do sudo -u minecraft,
                or specifically sudo -u minecraft /home/minecraft/server/start.sh,
                without a password.

              2. Do sudo -u minecraft sleep 0 in your script before the tmux command. 
                This will ask you for your password. 
                Subsequent sudo commands for the next few minutes
                will not require a password.






              share|improve this answer


























                0












                0








                0







                Two approaches:




                1. Edit /etc/sudoers to allow your user to do sudo -u minecraft,
                  or specifically sudo -u minecraft /home/minecraft/server/start.sh,
                  without a password.

                2. Do sudo -u minecraft sleep 0 in your script before the tmux command. 
                  This will ask you for your password. 
                  Subsequent sudo commands for the next few minutes
                  will not require a password.






                share|improve this answer













                Two approaches:




                1. Edit /etc/sudoers to allow your user to do sudo -u minecraft,
                  or specifically sudo -u minecraft /home/minecraft/server/start.sh,
                  without a password.

                2. Do sudo -u minecraft sleep 0 in your script before the tmux command. 
                  This will ask you for your password. 
                  Subsequent sudo commands for the next few minutes
                  will not require a password.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered 1 hour ago









                G-ManG-Man

                13.8k93870




                13.8k93870






















                    cory171185 is a new contributor. Be nice, and check out our Code of Conduct.










                    draft saved

                    draft discarded


















                    cory171185 is a new contributor. Be nice, and check out our Code of Conduct.













                    cory171185 is a new contributor. Be nice, and check out our Code of Conduct.












                    cory171185 is a new contributor. Be nice, and check out our Code of Conduct.
















                    Thanks for contributing an answer to Unix & Linux Stack Exchange!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f513503%2fhow-would-i-have-a-script-which-opens-a-tmux-session-and-then-changes-to-differe%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Taj Mahal Inhaltsverzeichnis Aufbau | Geschichte | 350-Jahr-Feier | Heutige Bedeutung | Siehe auch |...

                    Baia Sprie Cuprins Etimologie | Istorie | Demografie | Politică și administrație | Arii naturale...

                    Nicolae Petrescu-Găină Cuprins Biografie | Opera | In memoriam | Varia | Controverse, incertitudini...