Transitioning from Windows to Linux is a pleasant experience, but not one for the faint-hearted. There are a lot of things that can take a while to learn: the different filesystem structure, new applications, and the terminal.
If you’ve been stuck with Windows for a long time, chances are that you are not going to switch to Linux entirely in one day and forget about Windows. You probably still want to access resources on that Windows machine, and that, for me, was one of the biggest hassles. Not because it is difficult, but because there are several steps along the way (on both the Windows and Linux sides), and it is really easy to miss one.
The commands in this article have been executed on Kubuntu, and are likely to work on any similar Debian-based distribution.
Let’s say you’re running an SVN server on your Windows machine, and you’d like to communicate with it from Linux. In order to find that Windows machine, you could try looking up its IP. However, home networks typically use DHCP, which means that a machine’s IP tends to change over time. So while using the IP could work right now, you will likely have to update your configuration again tomorrow.
You could allocate a static IP for this, but a much easier option is to simply look up the name of the machine instead of the IP. You can find out the machine’s name using the
hostname command, which works on both Windows and Linux. Once we know the name of the Windows machine, we can try
pinging it from Linux to see whether we can reach it:
daniel@orion:~$ ping windowspc ping: windowspc: No address associated with hostname
That does not look very promising. Unfortunately, Linux machines can’t resolve Windows DNS out of the box. In order to get this working, we first need to install a couple of packages:
daniel@orion:~$ sudo apt install winbind libnss-winbind
After that, we need to edit the
/etc/nsswitch.conf file, which on a fresh Kubuntu installation would look something like this:
# /etc/nsswitch.conf # # Example configuration of GNU Name Service Switch functionality. # If you have the `glibc-doc-reference' and `info' packages installed, try: # `info libc "Name Service Switch"' for information about this file. passwd: files systemd group: files systemd shadow: files gshadow: files hosts: files mdns4_minimal [NOTFOUND=return] dns networks: files protocols: db files services: db files ethers: db files rpc: db files netgroup: nis
Use whichever editor you prefer, to update the highlighted line above to this:
hosts: files mdns4_minimal [NOTFOUND=return] dns wins mdns4
If you try pinging again, it should now work. No restart is necessary.
daniel@orion:~$ ping windowspc PING windowspc (192.168.1.73) 56(84) bytes of data. 64 bytes from 192.168.1.73 (192.168.1.73): icmp_seq=1 ttl=128 time=614 ms 64 bytes from 192.168.1.73 (192.168.1.73): icmp_seq=2 ttl=128 time=519 ms 64 bytes from 192.168.1.73 (192.168.1.73): icmp_seq=3 ttl=128 time=441 ms 64 bytes from 192.168.1.73 (192.168.1.73): icmp_seq=4 ttl=128 time=55.2 ms 64 bytes from 192.168.1.73 (192.168.1.73): icmp_seq=5 ttl=128 time=2.67 ms 64 bytes from 192.168.1.73 (192.168.1.73): icmp_seq=6 ttl=128 time=510 ms 64 bytes from 192.168.1.73 (192.168.1.73): icmp_seq=7 ttl=128 time=430 ms 64 bytes from 192.168.1.73 (192.168.1.73): icmp_seq=8 ttl=128 time=48.9 ms ^C --- windowspc ping statistics --- 9 packets transmitted, 8 received, 11.1111% packet loss, time 12630ms rtt min/avg/max/mdev = 2.671/327.520/613.590/232.503 ms
Resolving the hostname can sometimes take time. If you’re using a client application that can’t seem to resolve the Windows machine name, give it a few seconds, or try pinging it again. It should work after that.
Update 5th December 2019: If this doesn’t work, there are a couple of things I’ve seen recommended. One is to move the
wins entry in
/etc/nsswitch.conf to right after the
files entry. Another is to try restarting the
winbind service and see whether it makes a difference:
sudo systemctl restart winbind.
Windows File Share
Another important aspect to interoperability between Windows and Linux is how to pass files between them. Fortunately, Linux comes with software called Samba that allows it to see and work with Windows file shares.
Before we do this, we need to create a shared folder on Windows. To do this, create a new folder (e.g. named share) on your Windows machine, then right click on it and select Properties. In the Sharing tab, there’s a button that says Advanced Sharing:
Click on it, and in the next modal window, check the box that says Share this folder. You can then OK all the way out without making further changes.
Through Kubuntu’s file manager application, called Dolphin, you can navigate to any Windows file shares visible on the network, even if you haven’t done the setup in the previous section.
To do this, select Network from the left, then double-click Shared Folders (SMB):
Next, select Workgroup:
You should now be able to see any Windows or Linux machines. Select the icon with the name of your Windows machine.
You should be prompted for credentials, and at that stage enter the same username and password that you use to login on Windows.
We can now see the shared folders on the Windows machine, including the shared folder we created earlier:
If, on the Windows side, we drop a file into that share folder, we can see it from Linux, and we are perfectly able to copy it over:
Unfortunately however, the same is not yet true in reverse. If we try to copy a file from the Linux machine into share, we get a lousy Access denied error:
It seems to be a permissions issue, so let’s go back on Windows and see what we might have missed. If we right click the folder and select Properties, we notice that the folder appears to be read-only:
This in fact has nothing to do with the problem, and attempting to change it has no effect.
Instead, what we need to do is go back to that Advanced Sharing modal window (via the Advanced Sharing button in the Properties’ Sharing tab). Click the Permissions button to see who has access to that folder. It seems like Everyone is listed but only has Read access. Please resist the temptation or other internet advice to give full access to Everyone, and instead look up the user you normally use to log into Windows:
You can then give your user full control:
You can now drop a file into the share folder from Linux without any problems:
Talking to a Windows machine from Linux is possible, but slightly tricky to set up.
In order for client applications on Linux to talk to server applications on Windows, install the
libnss-winbind packages, and edit
/etc/nsswitch.conf to enable DNS resolution for Windows machines. Use
ping to verify that the hostname is beig resolved.
To share files between Windows and Linux, set up a shared folder on Windows. Add your Windows user to the list of people who can access the folder, giving it both read and write permissions. Then, from Linux, use the file manager application’s existing Samba integration to reach and work with the shared folder.