Sharing linux directories with windows

How to share files between a Linux and Windows computer

Computer Hope

The easiest and most reliable way to share files between a Linux and Windows computer on the same local area network is to use the Samba file-sharing protocol. All modern versions of Windows come with Samba installed, and Samba is installed by default on most distributions of Linux.

Create a shared folder on Windows

First, create a shared folder on your Windows computer.

Following the steps below, creates a shared folder on your Windows computer that lets you access files in that folder on your Linux computer. With the right permissions you can also copy, edit, and delete files in that folder from your Linux computer.

  1. Open the Control Panel.
  2. Select the Network and Sharing Options or Network and Sharing Center option.
  3. Click the Change advanced sharing settings link in the left navigation menu.
  4. Click the Turn on Network Discovery and Turn on File and Print Sharing options.
  5. Click the Save changes button at the bottom of the Advanced sharing settings window.

Now, create a new folder to share or choose an existing folder that you want to share.

  1. Right-click the folder and select Properties.
  2. Go to the Sharing tab.
  3. To share the folder with another Windows account, click the Share button, add the account to grant permission to access the shared folder, and click the Share button.

If you shared the folder with another Windows account, you need to click the Advanced Sharing button, then click the Permissions button. Select the account, check the Allow box for the Change or Modify permission, and click OK.

  1. Click the Advanced Sharing button.
  2. On the Advanced Sharing window, check the box for Share this folder and click OK.
  3. The network path for the folder is now displayed above the Share button, indicating that it is now a shared folder. For example, it may look like \\YOURCOMPUTERNAME\Users\YourUserName\ShareFolderName. Make a note of this network folder path to use later on your Linux machine.

Access a Windows shared folder from Linux using Konqueror

Many Linux distributions use the KDE (K Desktop Environment) and the Konqueror file manager/browser. If you’re using this, you can follow these steps to access your Windows shared folder.

  1. Click the K menu icon.
  2. Select Internet ->Konqueror.
  3. In the Konqueror window that opens, click the Network Folders link, or type remote:/ in the address bar and press Enter .
  4. Click the Samba Shares icon.
  5. Click the icon of your Windows Home workgroup.
  6. Click the Workgroup icon.
  7. Click the icon for your computer.
  8. When prompted, enter the username and password for the Windows account that created the share.
  9. Click OK.
Читайте также:  How to install wine on kali linux

Access a Windows shared folder from Linux using Nautilus

Many Linux distributions, especially those that use the GNOME desktop environment, use the Nautilus file manager. If you’re using this, you can follow these steps to access your Windows shared folder.

  1. Open Nautilus.
  2. From the File menu, select Connect to Server.
  3. In the Service type drop-down box, select Windows share.
  4. In the Server field, enter the name of your computer.
  5. Click Connect.

Alternatively, in the Nautilus address bar, you can type smb://ComputerName/ShareName and press Enter . For example, when you created your Windows Share if the share name was listed as:

\\YOURCOMPUTERNAME\Users\YourUserName\ShareFolderName

Type smb://YOURCOMPUTERNAME/Users/YourUserName/ShareFolderName and press Enter . Note the smb: at the beginning, in Linux, use forward slashes instead of backslashes.

Access a Windows shared folder from Linux using the command line

You can also access your Windows shared folder from the Linux command line using the smbclient program.

  1. Open a terminal.
  2. Type smbclient at the command prompt.
  3. If you receive a «Usage:» message, smbclient is installed, and you can skip to the next step. However, if the command is not found, you need to install smbclient. Follow these steps to install it.
  1. If you use the apt package manager, the default on Linux systems such as Ubuntu or Debian, you can use the sudo apt-get install smbclient command.
  2. If you use the yum package manager, the default on Linux systems, such as CentOS, you can use the sudo yum install samba-client command.
  3. You can also download the Samba client directly at www.samba.org/samba/download/, which might be useful to you if you need or want to compile the program from the source code.

Источник

Mounting and mapping shares between Windows and Linux with Samba

Create an air of interoperability in your network with Samba. Your Windows and Linux systems can work together.

Samba share mounting and mapping

Great Linux resources

In my previous article, Interoperability: Getting started with Samba, I covered installing and configuring Samba shares on a Linux server. The real power of Samba comes when Windows clients can communicate with Linux file servers. In this article, I will cover how you can access Samba shares from both Linux and Windows clients.

Install the Samba client packages

To access Samba share from Linux clients we need to install a few Samba client packages.

On the client machine, install the samba-common and samba-client packages.

# yum install samba-client samba-common -y

Check for available shares

Let’s check if we can access our shares from the server. We can use either the hostname or ip address of the server. If you use the hostname , make sure DNS is working.

# smbclient -U user -L 192.168.1.122 Enter SAMBA\user's password: Sharename Type Comment --------- ---- ------- print$ Disk Printer Drivers myshare Disk my share IPC$ IPC IPC Service (Samba 4.9.1) user Disk Home Directories Reconnecting with SMB1 for workgroup listing. Server Comment --------- ------- Workgroup Master --------- ------- SAMBA SAMBA-SERVER

Create a directory that we can use as our mount point. I’m going to create a directory under /mnt , but you can use any directory you would like to. You may need to configure SELinux on that directory.

# mount -t cifs -o username=user //192.168.1.122/myshare /mnt/share Password for user@//192.168.1.122/myshare: ********

Now that we’ve mounted our share, we can check the mounts with the following command:

Let’s make that directory mount persistently so it can withstand a reboot. Using the text editor of your choice, edit the /etc/fstab file. You can do this in multiple ways, but I’m going to demonstrate two ways to mount the Samba share at boot in /etc/fstab .

The first option provides a username and password for the Samba user in the fstab .

//192.168.1.122/myshare /mnt/share cifs username=user,password=password,_netdev 0 0

The other option is to create a credential file. You can call this file anything, but I would like to call it cred . I would like to place credentials files in the home directory of the user. In our demonstration it will be /home/user/.cred .

//192.168.1.122/myshare /mnt/share cifs credentials=/home/user/.cred,_netdev 0 0

The _netdev option is important since we are mounting a network device. Clients may hang during the boot process if the system encounters any difficulties with the network.

Now create that .cred file inside the user’s home directory.

Next, add the Samba user’s username and password.

username=user password=password

Finally, mount all filesystems.

Access a share from a Windows client

I will be using Windows 10 as my client machine with a workgroup called SAMBA . We need to create a local user account on the Windows machine that matches the username and password of the Samba user account we created in my previous article. Although account creation is not necessary, this will make things simpler when accessing the share.

Like I mentioned above, this step is optional and you can skip it completely. Although there are multiple approaches to adding a new local user on a Windows machine, for the simplicity of this article I will be using PowerShell. Launch PowerShell as an administrator and issue following commands:

PS > $password = Read-Host -AsSecureString PS > New-LocalUser -Name “user” -Password $password

Now that we have created a new local user account matching the Samba user account, we can log in to Windows with our newly created user account.

Access a share from Windows Explorer

To access the Samba share from Windows Explorer, start typing the IP address to our share in the search area. I am using the hostname of the Samba server. In my case, it is centos . You can also access the share by using the IP address of the Samba server.

Browsing to the Samba share.

You might be prompted to enter the username and password to access the share if you skipped the local user creation process. If you get prompted for credentials, enter the Samba username and password we created in the previous article.

You will need to enter the Samba share path every time you want to access the share. There is a better way to access the share by mapping a drive to Samba share in Windows.

Mapping a drive to a Samba share

To map a drive to the Samba share, open PowerShell and issue following command:

PS > NET USE M: \\centos\myshare

Windows Explorer displaying a mapped network drive.

Accessing a Samba share on Linux and Windows is easy. With this basic setup, you will be able to access file shares from client machines in your network. With somewhat more configuration, you can deploy Samba shares in a domain environment. Samba can do more than file share. If you would like to learn more about Samba, read this article about Windows and Linux interoperability. This is a basic set up, but you can do so much more with Samba.

[ Want to test your sysadmin skills? Take a skills assessment today. ]

Источник

Оцените статью
Adblock
detector