How to enable samba/smb sharing in Ubuntu

1. Install the samba service

sudo apt-get install samba samba-common

2. Configure the shared directory

sudo chmod 777 /home/ -R

The meaning of this code is to /homeset the permissions of the directory and all its subdirectories and files so that all users can read, write and execute, which can be modified /home/work/as .

3. Add samba user

sudo smbpasswd -a 用户名

sudo smbpasswd -a Dwang

New SMB password:

Retype new SMB password:

Added user Dwang.

Here my system user is Dwang. If you add a user that is not a system account, you need to add it as a system user first, as follows:

sudo groupadd shareaccount -g 6000
sudo useradd  shareaccount -u 6000 -g 6000 -s /sbin/nologin -d /dev/null

groupadd shareaccount -g 6000: This command creates a shareaccountnew group named , and sets its GID to 6000.

useradd shareaccount -u 6000 -g 6000 -s /sbin/nologin -d /dev/null: This command creates a shareaccountnew user named , sets its UID to 6000, and sets the primary group it belongs to to shareaccountgroup. It also sets the login shell to /sbin/nologin, which disables users from logging into the system using the shell. Finally, it sets the user's home directory to /dev/null, which means the user will not have their own home directory. useraddcommand is used to create a new user in Ubuntu. -uoptions specify the UID of the new user, -goptions specify the new user's primary group, -soptions specify the login shell, and -doptions specify the user's home directory.

4. Modify the configuration file

sudo vi /etc/samba/smb.conf

Add the following at the end:

[share] 
    comment = Cyberspace
    path=/home
    create mask=0755
	directory mask=0755
    writable = yes
    valid users=dwang
    browseable=yes

[share] #Shared name, which affects the input when others visit
comment = Cyberspace #Shared description
path=/home #Shared path
create mask=0755
directory mask=0755
writable #Used to specify whether the shared path is writable
valid users # Specify which users can access the shared path, if you want to add multiple users, separate them with commas
browseable=yes #Browseable

5. Restart the samba service

sudo /etc/init.d/smbd restart

or

sudo service smbd restart

Note: The smb.conf configuration file has been modified, and the Samba service needs to be restarted to take effect

6. Access the shared directory under Windows:

Enter in resource manager

\\192.168.123.45\share

or add as a network location

The ip address here is the ip address of Ubuntu, which can ifconfigbe obtained by using the command; here sharecorresponds to the share name in your configuration file

Then prompt to enter the account password

reference:

https://blog.csdn.net/qq_41004932/article/details/117486105

Guess you like

Origin blog.csdn.net/m0_51484121/article/details/130319095