PowerShell / PowerShell/Win32-OpenSSH

ForceCommand not working, or how to force a client into a different shell

Open
#1,107 4 comments 4 reactions 1 assignee View on GitHub

@bagajjal is already working on this.

Since Jul 13, 2020.

0 - Backlog
Dominant language
No language data
Stars
8.3k
Forks
819
PR merge metrics
No merged PRs in 30d

Description

"OpenSSH for Windows" version

 PS C:\Program Files\OpenSSH> ((Get-Item (Get-Command sshd).Source).VersionInfo.FileVersion)
Get-Command : The term 'sshd' is not recognized as the name of a cmdlet, function, script file, or operable program.
...

It's v7.6.0.0p1-Beta though

Server OperatingSystem

((Get-ItemProperty "HKLM:\SOFTWARE\Microsoft\Windows nt\CurrentVersion\" -Name ProductName).ProductName)
Windows Server 2012 Standard Evaluation

Client OperatingSystem
PuTTY on Windows 10

What is failing
Cannot get the client to go straight into any other commands or shells.
In C:\ProgramData\ssh\sshd_config:

Match User domainadmin
ForceCommand python

In C:\Users\domainadmin\.ssh\rc:

python

/etc/passwd does not exist in windows.

Expected output

Python 2.7.14 (v2.7.14:84471935ed, Sep 16 2017, 20:25:58) [MSC v.1500 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>>

Actual output

domainadmin@mydomain@servername C:\Users\domainadmin>

I know the match block is working because if I put PasswordAuthentication no in there, it rejects domainadmin from logging on. I would try changing DefaultShell in the registry, but that is in HKLM and I only want it to be for one user, and adding DefaultShell to HKCU\SOFTWARE\OpenSSH had no effect.

Maybe I'm barking up the wrong tree here. I have an interactive python script that needs to be run as admin on the server over SSH, but I don't want the end user terminal to have access to an admin command prompt. My plan is to force the SSH connection to go straight into python c:\path\to\script.py and make sure the connection terminates when python completes. On Linux, I would just need to change the user's shell in /etc/passwd to /usr/bin/python /path/to/script.py, but in this case it needs to run on the Windows server. What am I doing wrong or how can I make this work?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.