Configure Anonymous Samba Sharing in Ubuntu
I was setting up some Ubuntu virtual machines for folding when I decided that I wanted to monitor them all via a single interface in Windows using FahMon. I also wanted to be able to alter the folder where the folding client resides in case I ever have to do a little maintenance. The easiest way to accomplish this is by setting up shared folders on the Ubuntu VMs and pointing FahMon to those folders. For me, security is not a concern as the files are not sensitive and the virtual machines are pretty secure on my LAN, so I decided to set up Samba shares on the VMs with anonymous sharing enabled.
In Windows, setting up a file share is relatively easy, but it takes a few more steps in Linux. Follow the steps below, and you will be on your way in minutes:
First, you will need to install Samba if it does not already exist on your system. Do so by running the following command at the terminal:
sudo apt-get install samba
Next, open the Samba config file in your text editor of choice, whether it be graphical or something like vi. Make sure you are logged in as root or that you launch the editor using sudo, otherwise the file will be read-only!
The path to the file is:
/etc/samba/smb.conf
At the end of the document, we are going to add the following:
[folding]
path = /home/DrNathan/folding
available = yes
read only = no
browsable = yes
public = yes
writable = yes
guest ok = yes
only guest = yes
guest account = nobody
The first line, surrounded by square brackets, specifies the name of the share. The next option specifies the full path to the shared folder. The subsequent settings are pretty straightforward, but the guest ok = yes, the only guest = yes and guest account = nobody settings are important for our anonymous sharing goal. They basically tell Samba that we want to allow only the guest account to access this folder, and that the guest account includes all anonymous users.
Now, save the file and close your editor. We now need to restart the Samba daemon with the following command entered at the command line:
sudo /etc/init.d/samba restart
You should now be able to access the share from your Windows machine by typing the path to the share in an explorer window. My path is the following:
\\foldingpc\folding
Where foldingpc is my Ubuntu machine’s name and folding is the share name.
If you try to edit, create, or delete a file in the folder, you will realize that you are denied access to the files. You need to complete one more step before having full anonymous access to the folder.
In a terminal window, browse to the folder just above your shared folder. In my case, this path is:
/home/DrNathan
You now need to change the permissions on the folder to grant yourself write permissions on the share. I did so by typing in the following:
sudo chmod 757 folding
This basically tells the system that I want to grant the group “others” (essentially anyone not the owner or in the same Linux group as the file owner) the ability to write to the directory named folding. The previous permissions on the directory were 755, so if you want to revert your changes, simply enter sudo chmod 755 folding at the terminal.
That’s it, now you should have full anonymous sharing configured on your system. What happens if you decide you would rather secure the folder using a password instead. Follow the link below for more:
Adding a user name and password requirement to our Samba share is not all that difficult. Most of what you need is already in place, we just need to change a few small items.
First off, let’s reverse the lax permissions we set on the shared folder by running chmod at the terminal again:
sudo chmod 755 folding
Now, we need to add a user and password combination to Samba. The user name you specify has to exist in Ubuntu before we can add a password. This user must also have at least read permissions on the folder you want to share. If you want to access the folder with a new user name, go ahead and add that to the system now. I’ll wait.
Done? Ok, let’s move on.
Samba keeps a list of users and passwords separate from the list of credentials Ubuntu records. To add a user to the Samba list, enter the following:
sudo smbpasswd -a [User Name]
Where [User Name] is the name of the user you want to add. I typed:
sudo smbpasswd -a DrNathan
After you enter this command, you will be prompted for a password. Enter your password and then confirm it when asked.
Now we’re ready to alter the configuration in the Samba configuration file. Open smb.conf in your favorite text editor once again. The full path is:
/etc/samba/smb.conf
We are going to remove the following lines from the configuration we added earlier:
guest ok = yes
only guest = yes
guest account = nobody
We are going to add the following line:
valid users = [User Name]
Where [User Name] is the user we configured earlier. I added:
valid users = DrNathan
The folder configuration should look like this when you are finished:
[folding]
path = /home/DrNathan/folding
valid users = DrNathan
available = yes
read only = no
browsable = yes
public = yes
writable = yes
Once again, restart the Samba daemon:
sudo /etc/init.d/samba restart
Now, try accessing the share from another machine on the network. You should be prompted for a user name and password.
That’s it, enjoy your new Samba share!
Thank you so much! This is exactly what I needed. I’m off to try this on the Ubuntu home server I’m setting up.