What are the steps for setting up a Linux Samba server?
The steps to set up Linux Samba are as follows:
- Install Samba server software:
- Run the command on Debian/Ubuntu: sudo apt-get install samba.
- Execute the command “sudo yum install samba” on CentOS/Fedora.
- Create a shared directory.
- Create a folder using the mkdir command to serve as a shared directory, for example: sudo mkdir /home/share.
- Set up Samba.
- Open the Samba configuration file /etc/samba/smb.conf with sudo nano /etc/samba/smb.conf.
- Add the following at the bottom of the file:
[share]
comment = Shared Folder
path = /home/share
writable = yes
guest ok = yes
browseable = yesIn which:
[share] is the name of the shared folder
comment is the description of the shared folder
path is the path of the shared directory
writable indicates whether the shared directory is writable
guest ok indicates whether anonymous access is allowed
browseable indicates whether it can be browsed - Create Samba user:
- Create a Samba user using the smbpasswd command to allow access to shared directories, for example: sudo smbpasswd -a username.
- Enter password and confirm password.
- Start the Samba service:
- Execute the following command on Debian/Ubuntu: sudo service smbd restart.
- Run the command on CentOS/Fedora: sudo systemctl restart smb.
- Set up a firewall.
- If you have a firewall, you need to open the relevant ports for Samba (default ports are 137-139 and 445), for example:
On Debian/Ubuntu, run the command: sudo ufw allow 137/udp
On CentOS/Fedora, run the command: sudo firewall-cmd –add-service=samba –permanent, then run sudo firewall-cmd –reload - Accessing Linux Samba through Windows.
- On Windows, open File Explorer, enter \\
, and then press the Enter key. - Enter your Samba username and password, then click on OK.
Now, you should be able to access the Samba shared directory on Linux from Windows.