How to Configure Samba to Share a Folder with Two Users on Ubuntu (with Read/Write and Read-Only Permissions)

Samba is a file sharing software that allows you to share files between Linux and Windows computers. It is a popular choice for home users and businesses alike.

In this article, we will show you how to configure Samba to share a folder with two users, one with read/write permissions and one with only read permissions, on Ubuntu.

Prerequisites

Before you begin, you will need the following:

  • A Linux computer running Ubuntu
  • Two user accounts
  • A shared folder

Steps

  1. Install Samba.
sudo apt install samba
  1. Create the shared folder.
sudo mkdir /shared
  1. Configure Samba's global options.

Open the Samba configuration file /etc/samba/smb.conf in a text editor.

Add the following lines to the [global] section:

security = user
passdb backend = tdbsam

This will set the security mode to user, which means that users will be authenticated using their local Linux accounts. The passdb backend option specifies the database that Samba will use to store user passwords. In this case, we are using the tdbsam database, which is a simple flat file database.

  1. Set up a user account for each user.

Create two user accounts, one for each user who will be accessing the shared folder. For example:

sudo adduser user1
sudo adduser user2
  1. Configure Samba share directory settings.

Add the following lines to the [share] section of the smb.conf file:

path = /shared
available = yes
valid users = user1,user2
write list = user1

This will create a share named share that is accessible to the users user1 and user2. The read only option is set to no, which means that both users will have read/write permissions to the shared folder. The write list option specifies the users who are allowed to write to the shared folder.

  1. Update the firewall rules.

If you are using a firewall, you will need to open the port that Samba uses. The default port is 139.

sudo ufw allow 139/tcp
  1. Restart Samba.
sudo systemctl restart smbd

Once you have completed these steps, the shared folder will be available to the two users. The user user1 will have read/write permissions to the folder, while the user user2 will only have read permissions.

 

Anil

Phasellus facilisis convallis metus, ut imperdiet augue auctor nec. Duis at velit id augue lobortis porta. Sed varius, enim accumsan aliquam tincidunt, tortor urna vulputate quam, eget finibus urna est in augue.

No comments: