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 /home
set 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 shareaccount
new group named , and sets its GID to 6000
.
useradd shareaccount -u 6000 -g 6000 -s /sbin/nologin -d /dev/null
: This command creates a shareaccount
new user named , sets its UID to 6000
, and sets the primary group it belongs to to shareaccount
group. 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. useradd
command is used to create a new user in Ubuntu. -u
options specify the UID of the new user, -g
options specify the new user's primary group, -s
options specify the login shell, and -d
options 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 ifconfig
be obtained by using the command; here share
corresponds 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