0

enter image description hereenter image description here

I am trying to login to Windows without password from a Linux server. I have already installed OpenSSH from GitHub and I'm able to do scp and ssh. I tried copying the authorized_keys to the Windows location. But it's still not working. The functionality should be no password prompt for running ssh or scp from linux environment to login/show windows directory.

I tried below commands:

cat .ssh/id_rsa.pub | ssh edh_win@xxx.xxx.xxx.xxx 'cat >> .ssh/authorized_keys'

ssh edh_win@xxx.xxx.xxx.xxx "chmod 700 .ssh; chmod 640 .ssh/authorized_keys"

But getting error not able to understand cat and chmod.

Updating the errors

'cat' is not recognized as an internal or external command,
operable program or batch file.

'chmod' is not recognized as an internal or external command,
operable program or batch file.

Do I need to install cygwin? If yes, please help with the implementation.

Any assistance is appreciated. Below is an image of the error.

image of the error

  • 1
    Have you googled cygwin ssh server install? The steps are install cygwin's sshd server, run the config, login. I'm not going to do this for you. – djsmiley2k - CoW May 3 '18 at 11:23
  • Let me try installing the same – Subash May 3 '18 at 11:35
  • @ djsmiley2k Still facing the same.Even though installed the cygwin. Attaching the screenshots in question.Dont know what I am missing here – Subash May 3 '18 at 12:54
2

I personally use http://www.freesshd.com/ which makes it simple.

Here are some steps from this link: https://shades-of-orange.com/post/Setting-up-freeSSHd-to-Connect-to-its-SFTP-Server-Using-SSH-Public-Key-Authentication

  1. Open an instance of freeSSHd and go to the Users tab. Add or Change a login to use Public Key (SSH only) authorization and enable SFTP access

  2. Navigate to the Authentication tab. There you'll find the path to the folder in which to deposit your public keys. If you plan to have more than a few, consider using a subfolder of the default one

  3. Open the public key folder in Windows Explorer and create a new empty text file there by the name of the login you've set up in step 1. Make sure the file name is exactly the same as the name of the user and don't add any file extension to it.

  4. Save your public key text into the file you created in previous step.

1

Here is a series of steps attached to establish passwordless SSH from Linux to Windows / Windows to Linux:

Note:

  • Open a PowerShell console with Administrator privileges and execute all the PowerShell commands mentioned below in that console only
  • System environment variable (Inside Path variable: C:\Windows\System32\OpenSSH\ or C:\Program Files\OpenSSH\ depending on the installation path of OpenSSH) should be set if SSH related commands are to be run from PowerShell console

For Windows Server 2019:

  • Make sure the Windows system is up to date (Updates from Microsoft for Windows should be installed)
  • Make sure the OpenSSH features are installed on windows viz. OpenSSH Server and OpenSSH Client
  • Go to Apps & Features
  • Select Manage Optional Features
  • OpenSSH Server and OpenSSH Client should be listed there. In case they are not listed, click on Add a feature, install them.

For Windows Server 2012 and 2016:

  • Download the OpenSSH bits from https://github.com/PowerShell/Win32-OpenSSH/wiki/Install-Win32-OpenSSH (OpenSSH-Win64.zip)
  • Extract the contents into a folder named OpenSSH
  • Place the directory inside C:\Program Files\
  • Follow the steps 4-6 mentioned on https://github.com/PowerShell/Win32-OpenSSH/wiki/Install-Win32-OpenSSH :
  • In an elevated PowerShell console, run the following:

    powershell.exe -ExecutionPolicy Bypass -File install-sshd.ps1

  • Open the firewall for sshd.exe to allow inbound SSH connections by executing:

    New-NetFirewallRule -Name sshd -DisplayName 'OpenSSH Server (sshd)' -Enabled True -Direction Inbound -Protocol TCP -Action Allow -LocalPort 22

  • Start sshd and ssh-agent (this will automatically generate host keys under %programdata%\ssh if they don't already exist) by executing:

    net start sshd

    net start ssh-agent

  • Make sure the environment variable path is setup as mentioned in the Note above.


Common Steps for Windows Server 2012/2016/2019:

  • Execute the PowerShell commands:

    Set-Service ssh-agent -StartupType Automatic

    Set-Service sshd -StartupType Automatic

    Get-Service -Name ssh-agent,sshd

  • This should show the status as Running for both services

  • If they are not running, open Services and start them, viz. OpenSSH Server and OpenSSH Authentication Agent.

  • Execute the PowerShell command for public-private key pair generation on Windows host:

    ssh-keygen.exe

  • Follow the prompts with Enter key or ‘yes’, if prompted, which would generate the public and private key for the Windows host.

  • Create a file (with no extension) named administrators_authorized_keys at path C:\ProgramData\ssh\ on Windows host with command:

    New-Item -ItemType file administrators_authorized_keys

  • Copy the public key from the Linux host path /root/.ssh/id_rsa.pub to be appended in the file at path C:\ProgramData\ssh\administrators_authorized_keys on Windows machine [ This is for password less SSH from Linux to Windows host]

  • If the file id_rsa.pub does not exist at the above path, run the command ssh-keygen on Linux host terminal and follow the prompts with Enter key or yes, if prompted, to generate the private and public key on Linux host. (Typical prompts would be like what we encountered on Windows host.)

  • Copy the public key from Windows host C:\Users\Administrator.ssh\id_rsa.pub to be appended in the file at path /root/.ssh/authorized_keys on Linux host [This is for password less SSH from Windows to Linux host]

  • If the file authorized_keys does not exist on the Linux host, create one:

    touch authorized_keys (at location /root/.ssh/ )

  • Execute the following commands in PowerShell console [For permission settings]:

    icacls C:\ProgramData\ssh\administrators_authorized_keys /remove "NT AUTHORITY\Authenticated Users"

    icacls C:\ProgramData\ssh\administrators_authorized_keys /inheritance:r

    Restart-Service -Name sshd, ssh-agent -Force

  • Successful execution of all the steps mentioned above would allow password less SSH between Linux and Windows host, both ways.


Typical relevant locations on Windows host:

  • C:\Windows\Sytem32\OpenSSH\
  • C:\Program Files\OpenSSH\
  • C:\Users\Administrator.ssh\
  • C:\ProgramData\ssh\

References:

0

The errors say it all.

More or less, your ssh server provides... well, an ssh server. It dosen't have the 'unix' style or linux coreutils you're trying to run by default.

While swapping this ssh server for cygwin might help - what you literally need to do is understand what you're doing and not presume linux commands will work.

You can probably get cat on windows - through various native packages of it like the ones bundled with git or GOW

The permissions model probably works differently so you need to do it with native tools.

It needs some reading but this suggests "only System, Administrators and owner can have access"- and this post suggests you can use ICACLS to set the appropriate permissions.

The takeaway is - well you got to understand your tools and realise that you're not going to find the same environment everywhere.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.