samba configuration shared user home directory

Keywords: Operation & Maintenance sudo openssh Windows network

1. Install samba first

sudo apt-get update
sudo apt-get install samba openssh-server

2. Edit Samba configuration file

sudo cp /etc/samba/smb.conf /etc/samba/smb.conf.bak
sudo vi /etc/samba/smb.conf

Find the [homes] item, which is commented out by default, cancel the comment, and then modify the specific content as follows:

#======================= Share Definitions =======================

# Un-comment the following (and tweak the other settings below to suit)
# to enable the default home directory shares. This will share each
# user's home directory as \\server\username
[homes]
   comment = Home Directories
   browseable = no

# By default, the home directories are exported read-only. Change the
# next parameter to 'no' if you want to be able to write to them.
   read only = no

# File creation mask is set to 0700 for security reasons. If you want to
# create files with group=rw permissions, set next parameter to 0775.
   create mask = 0755

# Directory creation mask is set to 0700 for security reasons. If you want to
# create dirs. with group=rw permissions, set next parameter to 0775.
   directory mask = 0755

# By default, \\server\username shares can be connected to by anyone
# with access to the samba server.
# Un-comment the following parameter to make sure that only "username"
# can connect to \\server\username
# This might need tweaking when using external authentication schemes
   valid users = %S

After deleting redundant information, i.e.:

#======================= Share Definitions =======================
[homes]
   comment = Home Directories
   browseable = no
   read only = no
   create mask = 0755
   directory mask = 0755
   valid users = %S

After the above modification, wq saves and exits!

3. Restart samba service:

sudo service smbd restart && service nmbd restart
# sudo service restart smbd
# sudo service restart nmbd

4. Add a samba account corresponding to an existing user:

If I already have a user named landaliming, now I can open samba account for lim:

sudo smbpasswd -a landaliming

Enter the password twice as prompted.

5. Now you can test. Enter the samba address in Window to try to log in:

\\10.0.0.2\lim
#Note the path here, not \ home\lim

6. At this time, windows should pop up a window asking for user name and password

7. Map network drive

Posted by digitalhuman on Sun, 12 Jan 2020 09:30:35 -0800