File shares are important for collaboration in any network. In this series of articles, I will show you how Samba can help you set up and serve file shares on Linux servers that are accessible from both Linux and Windows clients.
What is Samba?
Before we dive in and set up file shares, let's cover what Samba is and what it can do for you.
Samba is a suite of applications that implements the Server Message Block (SMB) protocol. Many operating systems, including Microsoft Windows, use the SMB protocol for client-server networking. Samba enables Linux / Unix machines to communicate with Windows machines in a network.
Samba is open source software. Originally, Samba was developed in 1991 for fast and secure file and print share for all clients using the SMB protocol. Since then it has evolved and added more capabilities. Today Samba provides a suite of applications enabling seamless networking and interoperability between *nix and Windows.
Install the Samba packages
In this example, I'm using CentOS 8 with the hostname centos as my Samba server with an IP address of 192.168.1.122. The only package you will need to install is Samba, but I would like to include other client tools like samba-common and samba-client to test out our shares later.
# yum install samba samba-client samba-common -y
Create a directory to share and set its permissions
Once you’ve installed the required packages on the server, let's create a directory and provide the required permissions on the directory. Create a directory called share on our root directory. You can name this directory anything you want to, and give it read, write and execute permissions. In this example, we will rely on the Samba configuration to control read, write access to the shared directory.
# mkdir /share
# chmod -R 777 /share
Configure a share
Now that we have installed necessary packages, it's time to configure the shared directory. The configuration file is located under /etc/samba. Using your favorite text editor, append the following to /etc/samba/smb.conf. Leave the rest of the configuration file as is and this should be good for our setup.
# vim /etc/samba/smb.conf
[myshare]
comment = My share
path = /share
read only = No
I have created a share called myshare and provided a path to the share, which in our case is located at /share. I then gave it read/write permissions with read only = No. There are many other configuration parameters that you may pass here, but for our setup these settings are good.
Check the Samba configuration
Samba provides a tool to check our configuration file. We can check if our configuration file has any errors by using the testparm command.
# testparm
Next, we need to create a Samba user account, so that Samba can communicate in Samba sessions with shares. The smbpasswd command has several functions depending on if you run the command as root or as a standard user. If you issue smbpasswd without any arguments as a non-root user, by default smbpasswd will change the current logged in user's Samba password. When you run smbpasswd command as root, you will be able to create new Samba accounts. You can create a Samba account only for existing Linux user accounts.
# smbpasswd -a user
New SMB password:
Retype new SMB password:
We need to configure SELinux on the /share directory so the Samba service has proper permissions.
# semanage fcontext -a -t samba_share_t "/share(/.*)?"
# restorecon -R -v /share
Next, we need to enable and start the smb and nmb services.
# systemctl enable smb
# systemctl start smb
#systemctl enable nmb
#systemctl start nmb
If you have firewalld running on your server, we need to configure it to allow Samba traffic. You can do so by using the firewall-cmd command. Don't forget to make those changes permanent and reload firewalld.
Now we have our services enabled and started. We can check to see if the share is available from the server by using the smbclient tool. This is the reason I have installed the Samba client tools on the local machine. The command uses the following syntax:
smbclient -U <samba username we created above> -L <ip address of server>
# smbclient -U user -L 192.168.1.122
Enter SAMBA\user's password:
Let's check if we can access the share by issuing the following command on the server:
# smbclient -U user //192.168.1.122/myshare
Enter SAMBA\user's password:
Try "help" to get a list of possible commands.
smb: \>
Wrap up
We have installed and configured the Samba file share service on our Linux server. We were able to access those shares on the local machine. In the next article, we will set up one Linux client and one Windows 10 client to access share we just created.
[ Want to learn more about Linux system administration? Take a Red Hat system administration course. ]
저자 소개
Keerthi is aspiring Cloud, DevOps engineer, he has been working with Windows and Linux systems. He believes in continuous learning (CL) and continuous sharing (CS), on his way building his very own CL CS pipeline. When he is not playing in the CLI, you will find him playing Cricket.
유사한 검색 결과
Behind the scenes of RHEL 10, part 3
Alliander modernises its electricity grid with Red Hat for long-term reliability in balance with rapid innovation
The Overlooked Operating System | Compiler: Stack/Unstuck
Linux, Shadowman, And Open Source Spirit | Compiler
채널별 검색
오토메이션
기술, 팀, 인프라를 위한 IT 자동화 최신 동향
인공지능
고객이 어디서나 AI 워크로드를 실행할 수 있도록 지원하는 플랫폼 업데이트
오픈 하이브리드 클라우드
하이브리드 클라우드로 더욱 유연한 미래를 구축하는 방법을 알아보세요
보안
환경과 기술 전반에 걸쳐 리스크를 감소하는 방법에 대한 최신 정보
엣지 컴퓨팅
엣지에서의 운영을 단순화하는 플랫폼 업데이트
인프라
세계적으로 인정받은 기업용 Linux 플랫폼에 대한 최신 정보
애플리케이션
복잡한 애플리케이션에 대한 솔루션 더 보기
가상화
온프레미스와 클라우드 환경에서 워크로드를 유연하게 운영하기 위한 엔터프라이즈 가상화의 미래