Step 1: Install and Configure Samba
Samba is a tool for sharing files between Linux and Windows systems.
- Install Samba
sudo apt update sudo apt install samba -y
2. **Start Samba and enable it to run on boot**
```bash
sudo systemctl start smbd
sudo systemctl enable smbd
- Open the firewall to allow Samba
sudo ufw allow samba
4. **Create a Samba User**
- Add a new user (skip if the user already exists):
```bash
sudo useradd -M -s /sbin/nologin username
```
- Set the Samba password:
```bash
sudo smbpasswd -a username
sudo smbpasswd -e username
```
### **Step 2: Set Up a Shared Folder**
1. **Create the shared folder**
```bash
mkdir -p /var/shared
sudo chmod 777 /var/shared
-
Edit the Samba configuration file
- Open the configuration file:
sudo vim /etc/samba/smb.conf
- Add the share settings to the end of the file:[shared] path = /var/shared browsable = no writable = yes read only = no guest ok = no create mask = 0777 directory mask = 0777
P.S. It's best to set both `read only` and `guest ok` to `no`. I once had a worm drop some files into my Samba share. - Open the configuration file:
-
Save and exit the configuration file
- Press
Ctrl+Oto save, andCtrl+Xto exit.
- Press
-
Restart the Samba service
sudo systemctl restart smbd
### **Step 3: Access the Shared Folder from Windows 11**
1. **Check your Ubuntu's IP address**
```bash
ip a
Take note of the IP address, which will look something like `192.168.x.x`.
2. Connect to the shared folder
- Open File Explorer on Windows 11.
- In the address bar, type:
\\<Ubuntu_IP>\SharedFolder
For example:
\\192.168.1.100\SharedFolder
- Test the connection If everything is working correctly, you should be able to see the contents of the shared folder.
Troubleshooting Tips
- Manually open the required ports for Samba
sudo ufw allow proto tcp from any to any port 137,138,139,445 sudo ufw status
2. **Check the Samba configuration file and directory permissions**
- Confirm that the share settings in `/etc/samba/smb.conf` are correct.
- Check the permissions of the shared folder:
```bash
ls -ld /var/shared
```
If necessary, adjust the permissions:
```bash
sudo chmod 777 /var/shared
```
3. **Check the Samba logs**
```bash
sudo tail -f /var/log/samba/log.smbd
- Use the IP address instead of the hostname
Use
\<IP 地址>\sharedin Windows to avoid potential name resolution issues.




























Comments