How to Share A Folder in Ubuntu 21.04 [Fix ‘net usershare’ returned error 255]

Want to share a folder for local network or home network access? Here’s the step by step picture guide for Ubuntu beginners.

Ubuntu has a built-in option to enable local network share via SMB/CIFS protocol. With it enabled, you can access the shared folder in same network using Windows, Linux, Mac OS, and mobile devices including Android and iOS.

1.) Install the Samba share service.

You don’t have to run any command to install and setup the service. Simply right-click on the desired folder, Network Share folder for instance, and click “Local Network Share” option.

In next window, check the box that says “Share this folder”. An dialog will pop-up asks you to install the service. Click on “Install service” button.

Then you can click on ‘Description‘ to see the package description in the drop-down box and finally click on “Install” button. Type user password and wait the process done.

2.) Enable and Configure share folder permissions:

Once installed the service, go back the “Folder Sharing” window or re-right-click on folder and select ‘Local Network Share’. Then do

  • check the box “Share this folder”.
  • type ‘Share name’ which will display in remote machine.
  • (optional) add short description in ‘Comment’ section.
  • Check “Allow others to create and delete files in this folder.” if need.
  • Enable ‘Guest access‘ for remote access without typing user & password.

Finally click on “Create Share” button.

3.) Fix net usershare returned error 255

If the current user is not the one created during Ubuntu installation, you may get into an error says:

‘net usershare’ returned error 255: net usershare: cannot open usershare directory /var/lib/samba/usershared. Error permission denied. You do not have permission to create a usershare. Ask your administrator to grant your permissions to create a share.

You got the error because the login user does not in the sambashare group. Solution is just add your user to the group:

  • Open terminal from system app launcher. When it opens, run command to get current user name:
    whoami
  • Then add user into the group. Replace merilyn in the case with your output in last command:
    sudo gpasswd sambashare -a merilyn
  • Restart samba service:
    systemctl restart smbd.service nmbd.service

Restart the service did not work in my case while log out and back in did. And finally re-do step 2.) to enable folder share.

4.) Set password for remote access

Not enabe ‘Guest access’? If so, you have to set a samba only password, so remote user can type your user name and this password to access the shared folder.

Open terminal from system app launcher and do:

  • get your username if you don’t even remember:
    whoami
  • set a samba only password (replace merilyn with whoami output):
    sudo smbpasswd -a merilyn

Type your login password (no visual feedback) when it asks for sudo. Then type the new samba only password and twice to confirm.

5.) How to access SMB shared folder

Firstly, you need to get either the hostname of local IP address for the Ubuntu machine. To do so, either go to Wifi/Network Settings, or run command in terminal:

  • To get hostname, run:
    hostname
  • To get the IP address, run:
    ip address

To access the shared folder in different system:
replace host_name_here with the hostname, and replace ip_here with the IP address. They are hirsute and 192.168.0.108 in the previous picture.

  • For Windows, go to “Start Menu -> Run” and then type either \\host_name_here or \\ip_here and hit Enter.
  • For Linux, it depends on your system. For Gnome Desktop, open file manager and go to “Other Locations”, under bottom “Connect to Server” box type smb://host_name_here or smb://ip_here and hit Enter.
  • For Mac OS, press “command + K” on keyboard to open Connect to Server dialog, type in smb://host_name_here or smb://ip_here and hit Enter.
Exit mobile version