How to add permissions to windows user in samba on ubuntu server

9,480

To be thorough:

First, create a samba user if you haven't already:

useradd sambauser
smbpasswd -a sambauser

Enter and confirm the password for sambauser.

Change that part of your /etc/samba/smb.conf to this:

[share]
comment = Ubuntu File Server Share
path = /srv/samba/share
valid users = sambauser
browsable = yes
writable = yes
write list = sambauser
create mask = 0755

Make sure that the directory and everything that might be inside has the proper ownership and permissions:

chown -R sambauser:sambauser /srv/samba/share
chmod -R 755 /srv/samba/share

Make sure that you have allowed samba through selinux with this command if it is enabled. If selinux is not enabled then you can skip this part:

chcon -R -t  samba_share_t /srv/samba/share

Lastly, make sure that the ports are open for samba on the firewall.

firewall-cmd --permanent --zone=public --add-port=445/tcp
firewall-cmd --permanent --zone=public --add-port=139/tcp
firewall-cmd --reload
systemctl restart firewalld

If using `iptables:

iptables -A INPUT -p tcp --dport 445 -j ACCEPT
iptables -A INPUT -p tcp --dport 139 -j ACCEPT
iptables-save
iptables-restore

Restart the samba service and then log in with the credentials of sambauser.

Share:
9,480

Related videos on Youtube

Matthew Tranmer
Author by

Matthew Tranmer

Updated on September 18, 2022

Comments

  • Matthew Tranmer
    Matthew Tranmer over 1 year

    I have this samba network drive configured in ubuntu server for my windows computer and i want to make it so i can read/write but other users can not read or write to the network drive. How can i edit the smb.conf so i can do this? this is my smb.conf at the moment:

    [share]
        comment = Ubuntu File Server Share
        path = /srv/samba/share
        browsable = yes
        guest ok = yes
        read only = no
        create mask = 0755
    
  • Matthew Tranmer
    Matthew Tranmer over 5 years
    i get a error when i try to access it it says: \\192.168.1.144\fileserver is not accessible
  • Eric Jurgens
    Eric Jurgens over 5 years
    make sure that the share path is owned by the user
  • Matthew Tranmer
    Matthew Tranmer over 5 years
    how do i do that?
  • Eric Jurgens
    Eric Jurgens over 5 years
    use the chown command to change owner of a file or folder. Look at the chown man page if you have questions about how to use chown.
  • Matthew Tranmer
    Matthew Tranmer over 5 years
    i get a error when running chcon -R -t samba_share_t /srv/samba/share. the error says: chcon: can't apply partial context to unlabeled file 'Misc'
  • Nasir Riley
    Nasir Riley over 5 years
    @matthewtranmer Is selinux enabled on your system?
  • Matthew Tranmer
    Matthew Tranmer over 5 years
    no it is not, how do i enable it?
  • Nasir Riley
    Nasir Riley over 5 years
    @matthewtranmer If it's not enabled then you can skip that part. I'll update the answer and you can go ahead and connect if you've done everything else. Be sure that you restart the samba service first.
  • Matthew Tranmer
    Matthew Tranmer over 5 years
    i still get the error message
  • Nasir Riley
    Nasir Riley over 5 years
    @matthewtranmer What error?
  • Matthew Tranmer
    Matthew Tranmer over 5 years
    when i try to access it on windows i get a error message saying (in brief) \\192.168.1.144\share is not accessible
  • Nasir Riley
    Nasir Riley over 5 years
    @matthewtranmer Make sure that samba is allowed through the firewall via my update. Then make sure that either firewalld or iptables are reloaded/restarted and that samba is also restarted. To be sure, run netstat -tanp | grep smb and make sure that smbd is listening.