How to share a storage drive on Linux using Samba

Home > Search > How-to
  by

Install

Use the apt-get or yum command to install Samba and CIFS.

~]# yum install samba
~]# yum install cifs-utils

 


Firewall

Allow Samba in iptables or firewalld. Do not forget to restart iptables or reload firewalld.

 


Configuration

By default, Samba is not configured to share a network drive. Attempting to connect to the share will produce an error.

 

To be able to mount or map the network drive, the /etc/samba/smb.conf file must have the path defined. 

To be able to create new files and modify existing files in the share, the /etc/samba/smb.conf file must have writeable = yes or read only = no. Both these configurations do the same exact thing. 

[share]
path = /srv/samba/share
writeable = yes

 

Without writeable = yes, an error will appear when attemtping to create a new file or modify an existing file.

 

If a CUPS print server is not being used, add the following to prevent a massive number of records in the log with this message: failed to retrieve printer list nt_status_unsuccessful.

printing = bsd
printcap name = /dev/null

 

Notice in the above example, path is /srv/samba/share. If this directory does not exist, create it.

[root@server1 ~]# mkdir /srv/samba
[root@server1 ~]# mkdir /srv/samba/share

 

Change the permission to read, write, execute for all users to the share.

[root@server1 ~]# chmod 0777 /srv/samba/share

 

Add a file to the /srv/samba/share directory.

[root@server1 ~]# touch /srv/samba/share/test1.txt

 

Ensure Samba is enabled, restart Samba, and ensure Samba is active and running.

[root@server1 ~]# systemctl enable smb
[root@server1 ~]# systemctl restart smb
[root@server1 ~]# systemctl status smb

 


SELinux

SELinux may be configured to refuse Samba connections. Use the sestatus command to ensure SELinux is enforcing.

[root@server1 ~]# sestatus | grep mode
Current mode: enforcing

 

View the SELinux label on /srv/samba/share. In this example, the output has var_t.

[root@server1 ~]# ls -dZ /srv/samba/share
drwxrwxrwx.  root  root  unconfined_u:object_r:var_t:s0  /srv/samba/share

 

Turn on Samba home directories and export read/write.

[root@server1 ~]# setsebool -P samba_enable_home_dirs on
[root@server1 ~]# setsebool -P samba_export_all_rw on

 

Ensure Samba home directories and export read/write are on.

[root@server1 ~]# /usr/sbin/getsebool -a | grep samba_enable_home_dirs.
samba_enable_home_dirs --> on

[root@server1 ~]# /usr/sbin/getsebool -a | grep samba_export_all_rw.
samba_export_all_rw --> on

 

Use apt-get or yum to install policycoreutils-python. This package contains semanage.

[root@server1 ~]# yum -y install policycoreutils-python

 

Configure SELinux to remain intact if the system is rebooted.

[root@server1 ~]# semanage fcontext -a -t samba_share_t "/srv/samba/share(./*)?"

 

Updates SELinux with these changes.

[root@server1 ~]# restorecon -R -v /srv/samba/share

 

View the SELinux label on /srv/samba/share. In this example, the output should now be samba_share_t instead of var_t.

[root@server1 ~]# ls -dZ /srv/samba/share
drwxrwxrwx.  root  root  unconfined_u:object_r:samba_share_t:s0  /srv/samba/share

 


Username / Password

When attempting to connect to the share, there will be a prompt to enter a username and password.

 

Use the smbpasswd command to add a users password to the SMB database.

[root@server1 ~]# smbpasswd -a jeremy
New SMB password: ********
Retype new SMB password: ********

 


You can now access this share from a different computer in our LAN.

 


Noperm

If using a Linux client, such as Ubuntu, add the noperm option to the mount command. The noperm option disables permissions check. If noperm is not used, permission denied will likely appear when attempting to write or save files to the share.

 



Add a Comment




We will never share your name or email with anyone. Enter your email if you would like to be notified when we respond to your comment.




Please enter in the box below so that we can be sure you are a human.




Comments