Samba Client Configure
After you have already set up a Samba server, we will see in this post how to install and connect a Windows or a Linux machine to that Samba server. There are a lot of ways to do it, and we will use both the terminal and the GUI way for Linux.
Samba Client on Linux
Using terminal and /etc/fstab
For a permanent mount of the network folders after a reboot, we can edit the fstab
file in order to mount the drives after a start up.
Mounting the Samba share
To mount a Samba share on Linux first you need to instal the cifs-utils
package.
On Ubuntu and Debian run:
sudo apt install cifs-utils
Next, create a mount point (It is important for the directory to exist before mounting):
sudo mkdir /mnt/smbuser
Mount the share using the following command:
sudo mount -t cifs -o username=username,uid=$(id -u),gid=$(id -g) //samba_hostname_or_server_ip/sharename /mnt/smbuser
For example, to mount a share named smbuser
on a Samba server with IP address 192.168.1.99
as user smbuser
to the /mnt/smbuser
mount point, with the current’s user ownership, you would run:
sudo mount -t cifs -o username=smbuser,uid=$(id -u),gid=$(id -g) //192.168.1.99/smbuser /mnt/smbuser
Credentials File
You can also create a credential file in order to not specify every time the password.
Create a credentials file in your home directory, e.g. /home/$USER/.smbuser
(replace $USER
with your username in the following commands):
user=smbuser
password=mySecretPassword
domain=192.168.1.99
Mount the shared folder, using the credentials file:
sudo mount -t cifs -o credentials=/home/$USER/.smbuser,uid=$(id -u),gid=$(id -g) //192.168.1.99/smbuser /mnt/smbuser
Edit fstab
Now in order for the mount to be persistent we have to edit /etc/fstab
. Append the following line:
//192.168.1.99/smbuser /mnt/smbuser cifs credentials=/home/$USER/.smbuser,uid=1000,gid=1000 0 0
For the uid
, gid
options, we have to add the id of the user we want to have ownership explicitly because fstab cannot run the previous commands. For Ubuntu the first non-root user has uid=gid=1000
After you add the entry to /etc/fstab type:
sudo mount -a
This will (re)mount all entries listed in /etc/fstab
.
Unmount folder
In order to unmount a folder, run:
sudo umount /mnt/smbuser
Using GUI
The default file manager (Nautilus) in Gnome has built-in option to access Samba shares.
- Open Files and click on “Other Locations” in the sidebar.
- In “Connect to Server”, enter the address of the Samba share in the following format:
smb://192.168.1.99/smbuser
- Click “Connect” and a login screen will appear.
- Select “Registered User”, enter the Samba username and password and click “Connect”.
- The files on the Samba server will be shown.
Using smbclient
You can also access samba with the command line tool smbclient
. To install on Ubuntu and Debian run:
sudo apt install smbclient
Connect to Samba with smbclient
The syntax to access a Samba share is as follows:
smbclient //samba_hostname_or_server_ip/share_name -U username
For example, to connect to a share named smbuser
on a Samba server with IP address 192.168.1.99
as user smbuser
you would run:
smbclient //192.168.1.99/smbuser -U smbuser
You will be prompted to enter the user password. Once you enter the password you will be logged into the Samba command line interface.
Try "help" to get a list of possible commands.
smb: \>
Samba Client on Windows
Windows users also have an option to connect to the Samba share from both command line and GUI. The steps below show how to access the share using the Windows File Explorer.
- Open up File Explorer and in the left pane right-click on “This PC” and select “Add Network Location”.
- Select “Choose a custom network location” and then click “Next”.
- In “Internet or network address”, enter the address of the Samba share in the following format
\\192.168.1.99\smbuser
. - Click “Next” and you will be prompted to enter the login credentials.
- In the next window you can type a custom name for the network location. The default one will be picked up by the Samba server.
- Click “Next” to move to the last screen of the connection setup wizard.
- Click “Finish” and the files on the Samba server will be shown.