Many don’t realize how easy it is to integrate Microsoft Windows and Linux resources together, particularly sharing files between Microsoft Windows and Linux hosts. I’m
We start by installing the Samba client:
$ sudo yum install samba-client
This will also install the dependant samba-common and samba-winbind-clients packages.
On Ubuntu, we would install the smbfs package:
$ sudo apt-get install smbfs
Let’s start by performing the simplest action: mounting an SMB/CIFS file share on our Linux host. To do this, we can use a variety of methods. Let’s start by using the mount command. The first step is to create a mount point:
$ sudo mkdir /mnt/winshare
And then we mount our share:
$ sudo mount -t cifs //winserver/files /mnt/winshare -o user=winuser,pass=winpass,dom=windomain
Here we’ve mounted the file share files on the Windows host winserver. We’ve passed in appropriate credentials, including a Windows user, password and the domain the user belongs to. If the file share exists and you are appropriately authenticated to it, then you should now be able to browse the share from your mount point, /mnt/winshare, on your Linux host.
$ ls -l /mnt/winshare
Obviously this file share will only last for the period the host is running; restarting the host will remove the share. You can make this mount more permanent by adding an appropriate entry in your /etc/fstab file:
//winserver/files /mnt/winshare cifs credentials=/etc/cifs.secret,noexec 0 0
This will perform the same mount operation, marking the mount as non-executable (the noexec) option. You will also need to create the cifs.secret file to hold your Microsoft Windows credentials (you could specify them on the /etc/fstab entry, but this is more secure).
$ sudo touch /etc/cifs.secret
Populate this file with your credentials:
Now we need to protect this file from casual browsing:
$ sudo chmod 0400 /etc/cifs.secret
We can then mount our share:
$ sudo mount /mnt/winshare
The share will be re-mounted during any subsequent reboot.
Another method to connect to a Microsoft Windows file share is the smbclient command. The smbclient command acts more like using an FTP client than mounting a share directly. You will still need to provide appropriate credentials and a domain. Launch the command like so:
$ smbclient //winserver/files -U winuser -W windomain
Here you will be connected to the files share on winserver using the user winuser in the domain windomain. You will be prompted for a password. Enter the appropriate password and you will be presented with a prompt:
You can then use FTP-like commands to work with files on this share; for example, you can use ls or dir to list the files, mget and mput to get and put files, and the exit command to leave the session.
In addition to both of these methods, if you are running at host with a GUI window manager you can use tools like Nautilus to connect to a Microsoft Windows share. This functionality is available on both Red Hat-like and Ubuntu hosts.
But your integration potential is not limited to file sharing. You can also share your local printers with Microsoft Windows users or use Microsoft Windows printers on your Linux host via the Linux CIFS client. On Red Hat and similar systems, use either the printer configuration tool GUI (access it via System => Administration => Printing menu) or access it from the command line using the system-config-printer command. On Ubuntu, a printer tool is available from the System => Administration => Printing menu.
This was first published in September 2010