Configuring a basic Samba server for file sharing between Linux and Windows systems
Christian is a RHEL Sysadmin at IBM:
- His RHEL Server: RHEL_Server_12647
- His username: christian.okperi
- His professional preference: competent RHEL Sysadmins NEVER run commands as root
- His certifications: CompTIA Linux+, LPIC 1, 2 and 3, LFCS, he is studying for his RHCSA exam
- His task: Configure a basic Samba server that allows file sharing between Linux and Windows systems.
He has to show a class of 15 RHCSA candidates how to perform this task. Please generate and explain the commands that he will need to perform to complete this task.
To complete the task of configuring a basic Samba server for file sharing between Linux and Windows systems, Christian can follow the steps below, ensuring that he adheres to his professional preference of not running commands as root. These commands assume that Christian has administrative privileges and can use sudo to execute commands with elevated privileges when necessary.
Install the Samba package:
- sudo dnf install samba
- This command installs the Samba package on the RHEL server. The dnf package manager is used in RHEL 8 and newer versions.
- Start and enable the Samba service:
- sudo systemctl start smb
sudo systemctl enable smb - These commands start the Samba service and configure it to start automatically at boot.
- sudo systemctl start smb
- Configure the Samba server:
- sudo cp /etc/samba/smb.conf /etc/samba/smb.conf.bak
sudo nano /etc/samba/smb.conf The first command creates a backup of the original smb.conf file. The second command opens the smb.conf file in the nano text editor for editing.
Inside the smb.conf file, Christian should add or modify the following lines:
Define a shared directory:
- [shared]
path = /path/to/shared_directory
writable = yes
valid users = @sambausers Replace "/path/to/shared_directory" with the actual path to the directory that should be shared. "sambausers" should be replaced with the name of a group containing the users who will have access to the shared directory.
Adjust the security settings:
Replace "/path/to/shared_directory" with the actual path to the directory that should be shared. "sambausers" should be replaced with the name of a group containing the users who will have access to the shared directory.
Adjust the security settings:
- security = user
This line ensures that user-level security is used for authentication.
- sudo cp /etc/samba/smb.conf /etc/samba/smb.conf.bak
- Create Samba users:
- sudo useradd -M -s /sbin/nologin username
sudo smbpasswd -a username The first command creates a Samba user without a home directory and with a restricted login shell. Replace "username" with the desired username for the Samba user. The second command sets the Samba password for the user.
Repeat these commands for each user who needs access to the Samba shares.
- sudo useradd -M -s /sbin/nologin username
- Restart the Samba service:
- sudo systemctl restart smb
- This command restarts the Samba service to apply the changes made in the configuration file.
Test the Samba server:
From a Linux system: Open a file browser and enter the following in the address bar:
- smb://RHEL_Server_12647/shared
Replace "RHEL_Server_12647" with the IP address or hostname of the RHEL server. If the shared directory is accessible and writable, the Samba configuration is working correctly.
From a Windows system: Open the File Explorer and enter the following in the address bar:
- \\RHEL_Server_12647\shared
- Replace "RHEL_Server_12647" with the IP address or hostname of the RHEL server. If the shared directory is accessible and writable, the Samba configuration is working correctly.
Christian can now demonstrate these steps to the class of RHCSA candidates, explaining each command and its purpose along the way.