Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switching the user (su) seems to interrupt the connection for submitting further commands #126

Open
LorenzKahl opened this issue Jan 5, 2016 · 0 comments

Comments

@LorenzKahl
Copy link

I'm successfully connecting to my server using agentForwarding. My problem is that I then need to switch the user using sudo /bin/su -l deploymentUser which seems to interrupt the connection for submitting further commands.

I can run the commands in this order using iTerm without any problems:

[lkahl@myremoteserver ~]$ whoami
lkahl
[lkahl@myremoteserver ~]$ sudo /bin/su -l deploymentUser
[deploymentUser@myremoteserver ~]$ whoami
deploymentUser
[deploymentUser@myremoteserver ~]$

Here is my test-setup in my Grunt file:

        sshconfig: {
            myremoteserver: {
                host: 'myremoteserver.com',
                agent: process.env.SSH_AUTH_SOCK,
                agentForward: true,
                username: '<%= deploymentSettings.username %>',
            }
        },
        sshexec: {
            deploy: {
                command: 'whoami; sudo /bin/su -l deploymentUser; whoami',
                options: {
                    config: 'myremoteserver',
                }
            }
        },

When I run the task with --verbose this is the output I get:

Running "sshexec:deploy" (sshexec) task
Verifying property sshexec.deploy exists in config...OK
File: [no files]
Options: config="myremoteserver", host=false, username=false, password=false, agent="", agentForward=false, port=22, proxy={"port":22}, ignoreErrors=false, minimatch={}, pty={}, suppressRemoteErrors=false, callback=undefined
Raw Options: config="myremoteserver", host=false, username=false, password=false, agent="", agentForward=false, port=22, proxy={"port":22}, ignoreErrors=false, minimatch={}, pty={}, suppressRemoteErrors=false, callback=undefined
Verifying property sshconfig.myremoteserver exists in config...OK
Options: config="myremoteserver", host="myremoteserver", username="lkahl", password=false, agent="/tmp/launch-fj7pif/Listeners", agentForward, port=22, proxy={"port":22}, ignoreErrors=false, minimatch={}, pty={}, suppressRemoteErrors=false, callback=undefined
Connection :: connect
Connection :: ready
Executing :: whoami; sudo /bin/su -l deploymentUser; whoami
lkahl
[deploymentUser@myremoteserver ~]$ 

And from this point on nothing happens... so the grunt task will never finish :-(

Is there any way to have the third command (whoami) executed after the userswitch and still get the output displayed in my grunt task.

I'm not a command line hero at all – I just guess that switching the user remotely also causes the terminal-process to switch/spawn to a new instance which doesn't get forwarded properly to the process grunt listens to...

Any ideas?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant