- Mounting and mapping shares between Windows and Linux with Samba
- More Linux resources
- Ubuntu Documentation
- Connect to a file server
- Writing URLs
- Types of servers
- Access Windows Shares from Linux
- ( a ) Mount Windows share using mount command
- Other solutions
- ( b ) Browse a Samba or MS Windows share using smbclient
- ( c ) Browse a Samba or MS Windows share in Nautilus (GUI Option)
- 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
Mounting and mapping shares between Windows and Linux with Samba
More 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.
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.
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.
Now, mount the share.
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 .
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 .
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.
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:
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.
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:
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. ]
Источник
Ubuntu Documentation
You can connect to a server or network share to browse and view files on that server, exactly as if they were on your own computer. This is a convenient way to download or upload files on the internet, or to share files with other people on your local network.
To browse files over the network, open the Files application from the Activities overview, and click Other Locations in the sidebar. The file manager will find any computers on your local area network that advertise their ability to serve files. If you want to connect to a server on the internet, or if you do not see the computer you’re looking for, you can manually connect to a server by typing in its internet/network address.
Connect to a file server
In the file manager, click Other Locations in the sidebar.
In Connect to Server , enter the address of the server, in the form of a URL . Details on supported URLs are listed below .
If you have connected to the server before, you can click on it in the Recent Servers list.
Click Connect . The files on the server will be shown. You can browse the files just as you would for those on your own computer. The server will also be added to the sidebar so you can access it quickly in the future.
Writing URLs
A URL , or uniform resource locator , is a form of address that refers to a location or file on a network. The address is formatted like this:
The scheme specifies the protocol or type of server. The example.com portion of the address is called the domain name . If a username is required, it is inserted before the server name:
Some schemes require the port number to be specified. Insert it after the domain name:
Below are specific examples for the various server types that are supported.
Types of servers
You can connect to different types of servers. Some servers are public, and allow anybody to connect. Other servers require you to log in with a username and password.
You may not have permissions to perform certain actions on files on a server. For example, on public FTP sites, you will probably not be able to delete files.
The URL you enter depends on the protocol that the server uses to export its file shares.
If you have a secure shell account on a server, you can connect using this method. Many web hosts provide SSH accounts to members so they can securely upload files. SSH servers always require you to log in.
A typical SSH URL looks like this:
When using SSH, all the data you send (including your password) is encrypted so that other users on your network can’t see it.
FTP is a popular way to exchange files on the Internet. Because data is not encrypted over FTP, many servers now provide access through SSH. Some servers, however, still allow or require you to use FTP to upload or download files. FTP sites with logins will usually allow you to delete and upload files.
A typical FTP URL looks like this:
Sites that allow you to download files will sometimes provide public or anonymous FTP access. These servers do not require a username and password, and will usually not allow you to delete or upload files.
A typical anonymous FTP URL looks like this:
Some anonymous FTP sites require you to log in with a public username and password, or with a public username using your email address as the password. For these servers, use the FTP (with login) method, and use the credentials specified by the FTP site.
Windows computers use a proprietary protocol to share files over a local area network. Computers on a Windows network are sometimes grouped into domains for organization and to better control access. If you have the right permissions on the remote computer, you can connect to a Windows share from the file manager.
A typical Windows share URL looks like this:
Based on the HTTP protocol used on the web, WebDAV is sometimes used to share files on a local network and to store files on the internet. If the server you’re connecting to supports secure connections, you should choose this option. Secure WebDAV uses strong SSL encryption, so that other users can’t see your password.
A WebDAV URL looks like this:
UNIX computers traditionally use the Network File System protocol to share files over a local network. With NFS, security is based on the UID of the user accessing the share, so no authentication credentials are needed when connecting.
Источник
Access Windows Shares from Linux
Q. How do I Access Windows share from Linux command prompt? I would like to be able to access shared folders on Windows machines from my Linux system.
A. There are two ways. Use command line tool called smbclient or you can mount windows shares the mount command. Another option is use GUI tools. Please refer previous articles about access windows share from Linux:
( a ) Mount Windows share using mount command
This is simple way to share data between windows and linux system. You would like to access MS-Windows share called //windowsserver/sharename by mounting to /mnt/win directory under Linux system. Type the following command (replace username, windows server name, share name and password with actual values):
- No ads and tracking
- In-depth guides for developers and sysadmins at Opensourceflare✨
- Join my Patreon to support independent content creators and start reading latest guides:
- How to set up Redis sentinel cluster on Ubuntu or Debian Linux
- How To Set Up SSH Keys With YubiKey as two-factor authentication (U2F/FIDO2)
- How to set up Mariadb Galera cluster on Ubuntu or Debian Linux
- A podman tutorial for beginners – part I (run Linux containers without Docker and in daemonless mode)
- How to protect Linux against rogue USB devices using USBGuard
Join Patreon ➔
# mkdir -p /mnt/win
# mount -t smbfs -o username=winntuser,password=mypassword //windowsserver/sharename /mnt/win
# cd /mnt/win
# ls -l
For the share //windowsserver/sharename to be automatically mounted at every system start (after reboot), insert an option in the file /etc/fstab:
# vi /etc/fstab
Append following line (written in a single line)
//windowserver/share /mnt/win smbfs
auto,gid=users,fmask=0664,dmask=0775,iocharset=iso8859-15, credentials=/etc/sambapasswords 0 0
Next create the password file /etc/sambapasswords:
# vi /etc/sambapasswords
Now add following content:
username = winntuser
password = mypassword
Save and close the file. Make sure only root can access your file:
# chown 0.0 /etc/sambapasswords
# chmod 600 /etc/sambapasswords
Other solutions
( b ) Browse a Samba or MS Windows share using smbclient
( c ) Browse a Samba or MS Windows share in Nautilus (GUI Option)
🐧 Get the latest tutorials on Linux, Open Source & DevOps via
Источник
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.
Источник