Question

I have a Linux box (Ubuntu Server 13.04) which needs to run a job on a Windows 7 box (with cygwin installed) under a specific user's account. I have set up a password-less login to access the Windows machine through openSSH.

The problem I face is the following: when I manually ssh into the Win7 machine and launch the job everything is fine. However, when I launch the job using ssh winuser@winmachine command, I end up connecting to the Windows machine under the privileged sshd user 'cyg_server':

$ whoami
linuxuser
$ ssh winuser@Win7
$ whoami
winuser
$ exit
$ ssh winuser@Win7 "whoami; exit"
cyg_server
>> This should be 'winuser' too.

Why could this be happening? I have tried running ssh-host-config again to no avail. I don't see what parameters might influence this in sshd_config either.

Any help is greatly appreciated!

Was it helpful?

Solution

I had similar issues when I was connecting to a Cygwin machine using SSH. I used to have no problems logging on until one day I noticed that my path wasn't set correctly. I spent ages recreating the configuration files with ssh-host-config only to find my answer in the man page for ssh:

If command is specified, it is executed on the remote host instead of a login shell.

The problem was the alias I had used to connect to the machine had been changed to connect to a screen session automatically (screen -DR). That meant that if there wasn't already a screen session to attach to, screen was not being run as a child process of a user login shell and not inheriting any of the relevant user environment.

When you provide a command as an argument to ssh, the resulting command is run as a process started by cyg_server. Ensuring the SSH command is being run as part of a login shell should do what you want:

ssh winuser@Win7 "bash -l -c 'whoami; exit'"

Explanation (from the bash man page):

-c string If the -c option is present, then commands are read from string.
-l        Make bash act as if it had been invoked as a login shell.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top