- How to share files between a Linux and Windows computer
- Create a shared folder on Windows
- Access a Windows shared folder from Linux, using Konqueror
- Access a Windows shared folder from Linux, using Nautilus
- Access a Windows shared folder from Linux, using the command line
- How to Share Files and Folders Between Linux and Windows
- Samba makes it easier than you might think
- What Is Samba?
- Installing Samba
- Configuring Samba
- Adding Users
- Ready for Access
- Sharing Files between Ubuntu 20.04 and Windows Systems with Samba
- 1.1 Accessing Windows Resources from the GNOME Desktop
- 1.2 Samba and Samba Client
- 1.3 Installing Samba on an Ubuntu System
- 1.4 Configuring the Ubuntu Firewall to Enable Samba
- 1.5 Configuring the smb.conf File
- 1.5.1 Configuring the [global] Section
- 1.5.2 Configuring a Shared Resource
- 1.5.3 Removing Unnecessary Shares
- 1.6 Creating a Samba User
- 1.7 Testing the smb.conf File
- 1.8 Starting the Samba and NetBIOS Name Services
- 1.9 Accessing Samba Shares
- 1.10 Accessing Windows Shares from Ubuntu
- 1.11 Summary
How to share files between a Linux and Windows computer
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 machine.
- Open the Control Panel.
- Go to Network and Sharing Options.
- Go to Change Advanced Sharing Settings.
- Select Turn on Network Discovery and Turn on File and Print Sharing.
Now, create a new folder to share or choose an existing folder that you’d like to share.
- Right-click the folder and select Properties.
- Go to the Sharing tab.
- Above the Share button is the network name of the share you are creating. It should look like \\YOURCOMPUTERNAME\Users\YourUserName\ShareFolderName. Make a note of this network name to use later on your Linux machine.
- Click Share.
Access a Windows shared folder from Linux, using Konqueror
Many Linux distributions use the KDE desktop environment and the Konqueror file manager/browser. If this is what you are using, you can follow these steps to access your Windows shared folder:
- Click the K menu icon.
- Select Internet ->Konqueror.
- In the Konqueror window that opens, click the Network Folders link, or type remote:/ in the address bar and press Enter .
- Click the Samba Shares icon.
- Click the icon of your Windows Home workgroup.
- Click the Workgroup icon.
- Click the icon for your computer.
- When prompted, enter the username and password for the Windows account that created the share.
- Click OK.
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 this is what you’re using, you can follow these steps to access your Windows shared folder:
- Open Nautilus.
- From the File menu, select Connect to Server.
- In the Service type drop-down box, select Windows share.
- In the Server field, enter the name of your computer.
- Click Connect.
Alternatively, in the Nautilus address bar, you can type smb://ComputerName/ShareName and press Enter . For instance, when you created your Windows Share, if the share name was listed as:
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 share from the Linux command line using the smbclient program.
- Open a terminal.
- Type smbclient at the command prompt.
- If you receive a «Usage:» message, this means smbclient is installed, and you can skip to the next step. If the command is not found, however, you need to install smbclient. Follow these steps to install it.
Источник
How to Share Files and Folders Between Linux and Windows
Samba makes it easier than you might think
If your Linux machine is on a network, chances are you might want to share a directory (folder) or two to other users. Some Linux desktop environments (such as GNOME) make this incredibly simple. Some distributions and/or desktop environments, however, (such as Elementary OS) don’t offer a simple GUI for the sharing of folders.
Should you happen to be using a desktop environment that doesn’t make the process of sharing directories to your network a simple point-and-click affair, you’re not out of luck. Thanks to Samba (the underlying technology that makes this happen), you can still share those directories. It’s a bit tricker, but it’s not terribly hard.
What Is Samba?
Samba is an open-source software that enables Linux-based systems to communicate with Windows and macOS systems via the Common Internet File System (CIFS). Samba gets its name from the Server Message Block (SMB) protocol, which is at the heart of CIFS. Without Samba, directories on Linux wouldn’t be visible to Windows or macOS machines on your network.
For the purpose of this demonstration, we tested using Elementary OS 5 (Loki), which is based on Ubuntu Linux (so the process will be the same for any Ubuntu-based distribution) and Samba version 4.7.6.
Installing Samba
Chances are, you’re going to have to install Samba, as it is not included on most Linux desktop distributions. To install Samba, follow these steps:
Open a terminal window from your desktop menu.
Issue the command
sudo apt install samba samba-common -y
When prompted, type your user password.
Allow the installation to complete.
That’s all there is to the installation.
Configuring Samba
This is where things do get a bit challenging. What you must do is manually configure what are called Shares, with the Samba configuration file. In simple terms, a share is a directory you want to share with others on your network. We’ll create a very basic share.
The first thing to do is back up the original Samba configuration file. To do this, open a terminal window and issue the command
sudo cp -pf /etc/samba/smb.conf /etc/samba/smb.conf.bak
With the original file backed up, it’s now safe to edit the original. Issue the command
sudo nano /etc/samba/smb.conf
and scroll to the very bottom of that file. What we’re going to do is add a new share for the Public folder, found in your user home directory. Let’s say your username is jack. The full path to that Public folder would be /home/jack/Public. That’s important to know.
This new share will look like this:
[Public]
path = /home/jack/Public
browseable = yes
writeable = yes
read only = no
Save and close that file by typing Ctrl + x. Finally, restart Samba with the command
Adding Users
Now we have to add our Linux users to Samba. Why? Because although the Linux system recognizes the users, Samba does not. One thing to understand is that anyone wanting to have access to those shared directories will need to have an account on your machine. You can create anonymous access to those shared folders, but it lacks security (and we want to keep our machines as secure as possible).
Fortunately, there are only two simple commands to run. We’ll stick with our sample user, jack. The first command adds the user to Samba (requiring you type and verify a new password). This command is:
sudo smbpasswd -a jack
You might first be prompted for your users’ sudo password. Type that and then, when prompted, type and verify a new Samba password for the Samba user.
The second command enables the user for Samba. This command is:
sudo smbpasswd -e jack
Ready for Access
That’s it. The new user is added and will then be able to access the shares. If you go to another machine on your network, you should be able to access that share from your desktop’s file manager (with the username and password you configured using the smbpasswd command). How you access the share will depend upon the operating system and file manager used on the other machines.
Источник
Sharing Files between Ubuntu 20.04 and Windows Systems with Samba
Although Linux has made some inroads into the desktop market, its origins and future are very much server-based. It is not surprising therefore that Ubuntu has the ability to act as a file server. It is also extremely common for Ubuntu and Windows systems to be used side by side in networked environments. It is a common requirement, therefore, that files on an Ubuntu system be accessible to Linux, UNIX and Windows-based systems over network connections. Similarly, shared folders and printers residing on Windows systems may also need to be accessible from Ubuntu based systems.
Windows systems share resources such as file systems and printers using a protocol known as Server Message Block (SMB). In order for an Ubuntu system to serve such resources over a network to a Windows system and vice versa it must, therefore, support SMB. This is achieved using technology called Samba. In addition to providing integration between Linux and Windows systems, Samba may also be used to provide folder sharing between Linux systems (as an alternative to NFS which was covered in the previous chapter).
In this chapter we will look at the steps necessary to share file system resources and printers on an Ubuntu system with remote Windows and Linux systems, and to access Windows resources from Ubuntu.
1.1 Accessing Windows Resources from the GNOME Desktop
Before getting into more details of Samba sharing, it is worth noting that if all you want to do is access Windows shared folders from within the Ubuntu GNOME desktop then support is already provided within the GNOME Files application. The Files application is located in the dash as highlighted in Figure 23-1:
Once launched, select the Other Locations option in the left-hand navigation panel followed by the Windows Network icon in the main panel to browse available windows resources:
1.2 Samba and Samba Client
Samba allows both Ubuntu resources to be shared with Windows systems and Windows resources to be shared with Ubuntu systems. Ubuntu accesses Windows resources using the Samba client. Ubuntu resources, on the other hand, are shared with Windows systems by installing and configuring the Samba service.
1.3 Installing Samba on an Ubuntu System
The default settings used during the Ubuntu installation process do not typically install the necessary Samba packages. Unless you specifically requested that Samba be installed it is unlikely that you have Samba installed on your system. To check whether Samba is installed, open a terminal window and run the following command:
Any missing packages can be installed using the apt command-line tool:
1.4 Configuring the Ubuntu Firewall to Enable Samba
Next, the firewall currently protecting the Ubuntu system needs to be configured to allow Samba traffic.
If you are using the Uncomplicated Firewall (ufw) run the following command:
Alternatively, if you are using firewalld, run the firewall-cmd command as follows:
Before starting the Samba service a number of configuration steps are necessary to define how the Ubuntu system will appear to Windows systems, and the resources which are to be shared with remote clients. The majority of these configuration tasks take place within the /etc/samba/smb. conf file.
1.5 Configuring the smb.conf File
Samba is a highly flexible and configurable system that provides many different options for controlling how resources are shared on Windows networks. This flexibility can lead to the sense that Samba is overly complex to work with. In reality, however, many of the configuration options are not needed by the typical installation, and the learning curve to set up a basic configuration is actually quite short.
For the purposes of this chapter we will look at joining an Ubuntu system to a Windows workgroup and setting up a directory as a shared resource that can be accessed by a specific user. This is a configuration known as a standalone Samba server. More advanced configurations such as integrating Samba within an Active Directory environment are also available, though these are outside the scope of this book.
The first step in configuring Samba is to edit the /etc/samba/smb.conf file.
1.5.1 Configuring the [global] Section
The smb.conf file is divided into sections. The first section is the [global] section where settings can be specified that apply to the entire Samba configuration. While these settings are global, each option may be overridden within other sections of the configuration file.
The first task is to define the name of the Windows workgroup on which the Ubuntu resources are to be shared. This is controlled via the workgroup = directive of the [global] section which by default is configured as follows:
Begin by changing this to the actual name of the workgroup if necessary.
In addition to the workgroup setting, the other settings indicate that this is a standalone server on which the shared resources will be protected by user passwords. Before moving on to configuring the resources to be shared, other parameters also need to be added to the [global] section as follows:
The “netbios name” property specifies the name by which the server will be visible to other systems on the network.
1.5.2 Configuring a Shared Resource
The next step is to configure the shared resources (in other words the resources that will be accessible from other systems on the Windows network). In order to achieve this, the section is given a name by which it will be referred to when shared. For example, if we plan to share the /sampleshare directory of our Ubuntu system, we might entitle the section [sampleshare]. In this section a variety of configuration options are possible. For the purposes of this example, however, we will simply define the directory that is to be shared, indicate that the directory is both browsable and writable and declare the resource public so that guest users are able to gain access:
To restrict access to specific users, the “valid users” property may be used, for example:
1.5.3 Removing Unnecessary Shares
The smb.conf file is pre-configured with sections for sharing printers and the home folders of the users on the system. If these resources do not need to be shared, the corresponding sections can be commented out so that they are ignored by Samba. In the following example, the [homes] section has been commented out:
1.6 Creating a Samba User
Any user that requires access to a Samba shared resource must be configured as a Samba User and assigned a password. This task is achieved using the smbpasswd command-line tool. Consider, for example, that a user named demo is required to be able to access the /sampleshare directory of our Ubuntu system from a Windows system. In order to fulfill this requirement we must add demo as a Samba user as follows:
Now that we have completed the configuration of a very basic Samba server, it is time to test our configuration file and then start the Samba services.
1.7 Testing the smb.conf File
The settings in the smb.conf file may be checked for errors using the testparm command-line tool as follows:
1.8 Starting the Samba and NetBIOS Name Services
In order for an Ubuntu server to operate within a Windows network both the Samba (SMB) and NetBIOS nameservice (NMB) services must be started. Optionally, also enable the services so that they start each time the system boots:
Before attempting to connect from a Windows system, use the smbclient utility to verify that the share is configured:
1.9 Accessing Samba Shares
Now that the Samba resources are configured and the services are running, it is time to access the shared resource from a Windows system. On a suitable Windows system on the same workgroup as the Ubuntu system, open Windows Explorer and navigate to the Network panel. At this point, explorer should search the network and list any systems using the SMB protocol that it finds. The following figure illustrates an Ubuntu system named LINUXSERVER located using Windows Explorer on a Windows 10 system:
Double clicking on the LINUXSERVER host will prompt for the name and password of a user with access privileges. In this case it is the demo account that we configured using the smbpasswd tool:
Entering the username and password will result in the shared resources configured for that user appearing in the explorer window, including the previously configured /sampleshare resource:
Double clicking on the /sampleshare shared resource will display a listing of the files and directories contained therein.
If you are unable to see the Linux system or have problems accessing the shared folder, try mapping the Samba share to a local Windows drive as follows:
- Open Windows File Explorer, right-click on the Network entry in the left-hand panel and select Map network drive… from the resulting menu.
- From the Map Network Drive dialog, select a drive letter before entering the path to the shared folder. For example:
Enable the checkbox next to Connect using different credentials. If you do not want the drive to be mapped each time you log into the Windows system, turn off the corresponding check box:
With the settings entered, click on the Finish button to map the drive, entering the username and password for the Samba user configured earlier in the chapter when prompted. After a short delay the content of the Samba share will appear in a new File Explorer window.
1.10 Accessing Windows Shares from Ubuntu
As previously mentioned, Samba is a two way street, allowing not only Windows systems to access files and printers hosted on an Ubuntu system, but also allowing the Ubuntu system to access shared resources on Windows systems. This is achieved using the smbclient package which was installed at the start of this chapter. If it is not currently installed, install it from a terminal window as follows:
Shared resources on a Windows system can be accessed either from the Ubuntu desktop using the Files application, or from the command-line prompt using the smbclient and mount tools. The steps in this section assume that appropriate network sharing settings have been enabled on the Windows system.
To access any shared resources on a Windows system using the GNOME desktop, begin by launching the Files application and selecting the Other Locations option. This will display the screen shown in Figure 23-7 below including an icon for the Windows Network (if one is detected):
Selecting the Windows Network option will display the Windows systems detected on the network and allow access to any shared resources.
Alternatively, the Connect to Server option may be used to connect to a specific system. Note that the name or IP address of the remote system must be prefixed by smb:// and may be followed by the path to a specific shared resource, for example:
1.11 Summary
In this chapter we have looked at how to configure an Ubuntu system to act as both a Samba client and server allowing the sharing of resources with Windows systems. Topics covered included the installation of Samba client and server packages and configuration of Samba as a standalone server.
Источник