中文社区真的不太行,英文社区资源丰富很多
转载https://askubuntu.com/questions/1462387/trying-to-samba-share-a-folder-always-gives-errors的答案
Please see the following installation guideline. It can effectively solve the outstanding issue of 'net usershare' returned error 255..."
Install & Configure Samba
0.Remove your previously-installed samba
$ sudo apt-get purge samba samba-common
$ cd /home/username/Documents
$ sudo rm -rf share
1.Install samba
$ sudo apt update
$ sudo apt install samba samba-common
2.Check both version & path
1).Check version
$ samba -V
Version 4.15.13-Ubuntu
2).Installation path
$ whereis samba
3.Create share and authorize share
1).Show user's username (not host name)
$ whoami
The command reminds User to input the correct name for the next procedure.
2).Create share and authorize it
$ sudo mkdir /home/username/Documents/share
$ sudo chmod 777 /home/username/Documents/share
4.Write the following lines in smb.conf
1).Open smb.conf
$ sudo gedit /etc/samba/smb.conf
2).Write the command lines in smb.conf
[share]
comment = Samba on Ubuntu
path = /home/username/Documents/share
read only = no
browsable = yes
available = yes
writable = yes
public = yes
The above commands enable other Operation Systems such as Mac or Windows can access to Ubuntu 20.04. Please note the last three commands are essential to enable the Samba visible to Mac OS or Windows.
3).Save smb.conf
4).Close smb.conf
5.Restart Samba
$ sudo service smbd restart
6.Update the firewall rules to allow Samba traffic
$ sudo ufw allow samba
7.Set up user account
Please note the username and host name(or computer name) (username@hostname)
$ whoami
Show your username again in order to write a wrong name(such as host name)
$ sudo smbpasswd -a username
8.Connecting to Share
Please go to Files (of Ubuntu 20.04) on the left hand side
1).Open New Windows 2).click Other Locations 3).click share 4).Input Password twice for confirmation
9.Write Save a sample document
Write a sample text and save it into share
or
Copy an existing text into share
10.Set Mac OS
1).Go to Finder
2).Open Network
User can see the above written or saved sample text.
Notes:
- User can use the command of ifconfig to get your_ip_addres and then input samba://your_ip_address to connect the sever(Ubuntu). But the method has a little complex.