89

I can connect to Linux machines from Windows using PuTTY/SSH. I want to do the other way round - connect to a Windows machine from Linux.

Is this possible?

Renan
  • 17,136
vis
  • 1,017
  • See answer below: https://unix.stackexchange.com/a/427739/242983. OpenSSH is now supported natively by the latest update of Windows10. However, its not available for older versions. Please update your Windows10 before trying this. – alpha_989 Mar 02 '18 at 18:20
  • @Manishearth Because sometimes you just want something that works out of the box with no extra reading required. – Zimano May 01 '19 at 13:21
  • Also suggestion from https://pypi.org/project/pypsexec/ can help to execute remote windows commands – Ranganathan K G Feb 26 '21 at 06:51

8 Answers8

32

It depends on how you want to connect. You can create shares on the Windows machine and use smb/cifs to connect to the share.

The syntax would depend based on if you are in a domain or not.

# mount -t cifs //server/share /mnt/server --verbose -o user=UserName,dom=DOMAIN

You also have the ability to mount the $IPC and administrative shares. You can look into Inter-Process Communication for what you can do via the $IPC share.

There is always:

  • RDP
  • VNC
  • telnet
  • ssh
  • Linux on Windows

With the last 3 you need to install additional software.

VNC can be run from a stand-alone binary or installed.

For RDP most Linux systems either already have rdesktop installed or it is available in the package manager. Using rdesktop you only have to enable RDP connections to your Windows system and then you will be able to use RDP for a full GUI Windows console.

CharlesB
  • 424
  • 1
  • 5
  • 11
2bc
  • 3,978
11

If you are on Windows 10, you can install OpenSSH using the following Powershell script.

#change dns server to 8.8.8.8 so that the OpenSSH stuff can be downloaded
netsh interface ip set dns "Ethernet" static 8.8.8.8

#sleep for 60 s so that the DNS server has time to register
Start-Sleep -m 60

#check if OpenSSH is already installed or not
Get-WindowsCapability -Online | ? Name -like 'OpenSSH*'

# Install the OpenSSH Client
Add-WindowsCapability -Online -Name OpenSSH.Client~~~~0.0.1.0

# Install the OpenSSH Server
Add-WindowsCapability -Online -Name OpenSSH.Server~~~~0.0.1.0

# Check if OpenSSH is available
dism /Online /Get-Capabilities | findstr OpenSSH

# install the server and/or client features:
dism /Online /Add-Capability /CapabilityName:OpenSSH.Client~~~~0.0.1.0
dism /Online /Add-Capability /CapabilityName:OpenSSH.Server~~~~0.0.1.0

Install-Module -Force OpenSSHUtils

Repair-SshdHostKeyPermission -FilePath C:\Windows\System32\OpenSSH\ssh_host_ed25519_key

# start the ssh server daemon
Start-Service sshd

# This should return a Status of Running
Get-Service sshd

# add firewall rule to allow inbound and outbound traffic through port 22
New-NetFirewallRule -Name sshd -DisplayName 'OpenSSH Server (sshd)' -Service sshd -Enabled True -Direction Inbound -Protocol TCP -Action Allow -Profile Domain

Please note that this script will change the dns to Google dns. Because OpenSSH is not distributed with the default Windows10 distribution, it will actually download some files from the internet. So you need a working internet connection and a correct dns server, which is why I specified the static dns server, just in case you are behind a firewall or using a static ip with no dns server.

Once you have done this, you should figure out the ip address of the Windows host usign

ipconfig

Then from the Linux/Unix OS do

ssh username@Windows_ip

where username is the name of the account and Windows_ip is the ip address of the Windows computer you are trying to log into

Chris Davies
  • 116,213
  • 16
  • 160
  • 287
alpha_989
  • 443
  • On my windows installation, nothing except the first line is run. The response is "Sart-Sleep is not recognized as an internal or external command, operable program or batch file". So this is not quite as cookie-cutter as you'd like :-) – levitopher Dec 10 '18 at 20:54
  • 1
    An anonymous user has just noted in a (failed) edit that the line starting with Repair-SshdHostKeyPermission is not needed. I don't know whether or not this is true, but in case it is I don't want the note lost forever. – Chris Davies Feb 05 '19 at 23:30
  • Powershell should be open in administrator mode – alper Oct 15 '20 at 14:53
  • I am having following error: No match was found for the specified search criteria and module name 'OpenSSHUtils'. I am also having following error when I try to connect into it : Unable to negotiate with 192.168.137.1 port 22: no matching host key type found. Their offer: ssh-dss – alper Oct 15 '20 at 15:24
7

Yes, you can connect to Windows Machine from Linux client. But for that you have to host some kind of server(i.e. telnet, ssh, ftp or any other kind of server) on Windows machine and you should have the corresponding client on the Linux.

  • 3
    Since Windows is more dependent on its GUI than Linux, your best bet is probably RDP. – cjm Mar 24 '12 at 18:55
  • I don't think something like ftp was meant in the question. And telnet - ... really? – user unknown Mar 24 '12 at 22:41
  • 1
    Yeah, he probably meant ssh... – jcora Mar 25 '12 at 08:44
  • @pradeepchhetri and does Windows have some of this servers active by default? – H_7 Mar 25 '12 at 15:22
  • 3
    @H_7: Windows supports telnet and ftp server but by default they are not running. You have to make them run by: 1. Go to Control Panel -> 2. Programs And Features -> 3. Turn Windows features on or off. Here you can see the list of servers or client. You can run telnet or ftp server from here. – pradeepchhetri Mar 25 '12 at 15:38
  • as said above by pradeep you can access via telnet, you will get the command prompt and control the whole machine using a new addon called powershell. http://msdn.microsoft.com/en-us/library/windows/desktop/aa973757(v=vs.85).aspx – Abhishek Mar 26 '12 at 06:47
7

Maybe you would like to give RDP or software like teamviewer a try. Also you could install cygwin on your windows machine and configure it for ssh access, so you'd get a shell as you know it from linux when you connect by ssh.

mru
  • 438
5

If you use git on windows, congratulations, you can already ssh into your windows machine.

Just start the ssh server:

net start "C:\Program Files\Git\usr\bin\sshd.exe"

Then configure your firewall with this powershell command:

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

You should install openssh server on Windows Machine like openssh server on android.You can use putty on iinux machine to ssh to windows Machine.You can use netstat to check it after you can install openssh server on windows machine.

supriady
  • 167
  • 6
    why do you need putty on linux machines to ssh to windows? ssh it typically already installed on linux machines.. isnt it? – alpha_989 Mar 02 '18 at 18:05
1

I had this same issue tyring to ssh into a Windows server from my Ubuntu 18.04 machine.

If you are a Ubuntu user, you could try out Remmina.

It comes bundled with most Ubuntu distributions.

That's all.

I hope this helps

0

You can create an OpenSSH server on the windows machine, start the server and whola!

Read these for reference:

Y Y
  • 111