PuTTY error: /bin/bash Operation not permitted when connecting to Cygwin sshd

8,495

Solution 1

Here is a more direct way doing what the previous posts by Константин Брызгалов and Mun-dee say. Run a cygwin terminal as Administrator, then:

# stop the running sshd:
net stop sshd
# give the ssh user required privileges:
editrights -a SeTcbPrivilege -u cyg_server
editrights -a SeAssignPrimaryTokenPrivilege -u cyg_server
editrights -a SeCreateTokenPrivilege -u cyg_server
# restart sshd:
net start sshd

Solution 2

I spent a lot of time trying to solve the same problem. Accidentally stumbled upon a solution here:

https://cygwin.com/ml/cygwin/2015-08/msg00162.html

On cygwin server:

  1. Go to Control Panel > Administrative Tools.
  2. Select Local Security Policy > Local Policies > User Rights Assignment.
  3. Right-click Replace a Process Level Token and select Security or Properties.
  4. Click Add to add the account sshd is running on. ( cyg_server in my case )
  5. gpupdate
  6. Restart sshd service

Now try to connect via ssh ... I was successful

Solution 3

I had this problem and resolved it.

Initially I followed the answer from Константин Брызгалов and was able to login with a password, but could not get public key authentication working. (I had created a local cyg_server administrator account manually.)

On further investigation, I was reading this page and it said to avoid having both a domain and a local account. I checked and I did have both; apparently someone else in my organization is running a cygwin server and had already created a cyg_server on the domain, which was getting confused with my local account.

I deleted my local cyg_server account, uninstalled the sshd service, and reinstalled as described on that page, and everything worked perfectly out of the box. The trick was to say "no" to using the existing cyg_server account, and tell ssh-host-config to create a "cyg_server1" account. It created a local account and set everything up correctly. Specifically:

  1. cygrunsrv --stop sshd
  2. cygrunsrv --remove sshd
  3. Ctrl Panel > User Accounts > Manager User Accounts > (delete local cyg_server account)
  4. mkpasswd -l -d >/etc/passwd
  5. mkgroup -l -d >/etc/group
  6. ssh-host-config
    • overwrite = yes
    • strict = yes
    • CYGWIN = ntsec
    • user to run = cyg_server1
    • password = {...}

Checking user accounts you will see that cyg_server1 is indeed a local account but has additional setup.

Solution 4

I had forgotten that question, but in the end I solved my problem by rerunning the ssh-host-config in my Cygwin server install (fortunately I had RDP access as well).

That was all that was needed but I have no idea why it worked.

Solution 5

Thank you Константин Брызгалов for pointing me to the right direction, had the exact same problem.

A more thorough solution can ge found here: https://cygwin.com/faq.html#faq.using.sshd-in-domain There are actually 3 policy settings that need to have the cyg_server configured:

  • Act as part of the operating system (SeTcbPrivilege)
  • Create a token object (SeCreateTokenPrivilege)
  • Replace a process level token (SeAssignPrimaryTokenPrivilege)
Share:
8,495

Related videos on Youtube

sashoalm
Author by

sashoalm

Updated on September 18, 2022

Comments

  • sashoalm
    sashoalm over 1 year

    When trying to connect to an SSH server using PuTTY, I get an error:

    /bin/bash: Operation not permitted
    

    And then I get a message box saying:

    Connection closed by remote host
    

    This started happening unexpectedly today and I have no idea why, the SSH connection used to work fine before that.

    enter image description here

    What is causes this error, and is there any way to fix it?

    Edit: The server is a Windows box, not Linux, and it is running Cygwin's sshd. Also I found this post which I think might be relevant - https://cygwin.com/ml/cygwin/2016-03/msg00097.html

    • Mikael Kjær
      Mikael Kjær over 6 years
      Seems like /bin/bash is either deleted or your user doesn't have permissions to it. You should probably contact the administrator and ask him to fix it.
    • Zumo de Vidrio
      Zumo de Vidrio over 6 years
      Can you login with another user?
    • sashoalm
      sashoalm over 6 years
      @MikaelKjær Hm, if bash is missing wouldn't the error message be "command not found" or some such? Likely you're right about the permissions though.
    • sashoalm
      sashoalm over 6 years
      @ZumodeVidrio I asked one of my colleagues and she get the same error.
    • harrymc
      harrymc over 6 years
      This bash error is coming from the Linux server. The cause is maybe a bad command in the file .bashrc of the user profile you are connecting to.
    • sashoalm
      sashoalm over 6 years
      @harrymc It's a windows server with cygwin.
    • harrymc
      harrymc over 6 years
      If you don't know where .bashrc is located under cygwin, you could run on the server the command echo $HOME on the same user profile you are connecting to.