In my previous article, Interoperability: Getting started with Samba, I covered installing and configuring Samba shares on a Linux server. The real power of Samba comes when Windows clients can communicate with Linux file servers. In this article, I will cover how you can access Samba shares from both Linux and Windows clients.
Install the Samba client packages
To access Samba share from Linux clients we need to install a few Samba client packages.
On the client machine, install the samba-common
and samba-client
packages.
# yum install samba-client samba-common -y
Check for available shares
Let's check if we can access our shares from the server. We can use either the hostname
or ip address
of the server. If you use the hostname
, make sure DNS is working.
# smbclient -U user -L 192.168.1.122
Enter SAMBA\user's password:
Sharename Type Comment
--------- ---- -------
print$ Disk Printer Drivers
myshare Disk my share
IPC$ IPC IPC Service (Samba 4.9.1)
user Disk Home Directories
Reconnecting with SMB1 for workgroup listing.
Server Comment
--------- -------
Workgroup Master
--------- -------
SAMBA SAMBA-SERVER
Create a directory that we can use as our mount point. I'm going to create a directory under /mnt
, but you can use any directory you would like to. You may need to configure SELinux
on that directory.
# mkdir /mnt/myshare
Now, mount the share.
# mount -t cifs -o username=user //192.168.1.122/myshare /mnt/share
Password for user@//192.168.1.122/myshare: ********
Now that we’ve mounted our share, we can check the mounts with the following command:
# df -h
Persistent mount
Let's make that directory mount persistently so it can withstand a reboot. Using the text editor of your choice, edit the /etc/fstab
file. You can do this in multiple ways, but I'm going to demonstrate two ways to mount the Samba share at boot in /etc/fstab
.
# vim /etc/fstab
The first option provides a username and password for the Samba user in the fstab
.
//192.168.1.122/myshare /mnt/share cifs username=user,password=password,_netdev 0 0
The other option is to create a credential file. You can call this file anything, but I would like to call it cred
. I would like to place credentials files in the home directory of the user. In our demonstration it will be /home/user/.cred
.
//192.168.1.122/myshare /mnt/share cifs credentials=/home/user/.cred,_netdev 0 0
The _netdev
option is important since we are mounting a network device. Clients may hang during the boot process if the system encounters any difficulties with the network.
Now create that .cred
file inside the user's home directory.
# vim /home/user/.cred
Next, add the Samba user's username and password.
username=user
password=password
Finally, mount all filesystems.
# mount -a
Access a share from a Windows client
I will be using Windows 10 as my client machine with a workgroup called SAMBA
. We need to create a local user account on the Windows machine that matches the username and password of the Samba user account we created in my previous article. Although account creation is not necessary, this will make things simpler when accessing the share.
Like I mentioned above, this step is optional and you can skip it completely. Although there are multiple approaches to adding a new local user on a Windows machine, for the simplicity of this article I will be using PowerShell. Launch PowerShell as an administrator and issue following commands:
PS > $password = Read-Host -AsSecureString
PS > New-LocalUser -Name “user” -Password $password
Now that we have created a new local user account matching the Samba user account, we can log in to Windows with our newly created user account.
Access a share from Windows Explorer
To access the Samba share from Windows Explorer, start typing the IP address to our share in the search area. I am using the hostname
of the Samba server. In my case, it is centos
. You can also access the share by using the IP address of the Samba server.
You might be prompted to enter the username and password to access the share if you skipped the local user creation process. If you get prompted for credentials, enter the Samba username and password we created in the previous article.
You will need to enter the Samba share path every time you want to access the share. There is a better way to access the share by mapping a drive to Samba share in Windows.
Mapping a drive to a Samba share
To map a drive to the Samba share, open PowerShell and issue following command:
PS > NET USE M: \\centos\myshare
Wrap up
Accessing a Samba share on Linux and Windows is easy. With this basic setup, you will be able to access file shares from client machines in your network. With somewhat more configuration, you can deploy Samba shares in a domain environment. Samba can do more than file share. If you would like to learn more about Samba, read this article about Windows and Linux interoperability. This is a basic set up, but you can do so much more with Samba.
[ Want to test your sysadmin skills? Take a skills assessment today. ]
저자 소개
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.
채널별 검색
오토메이션
기술, 팀, 인프라를 위한 IT 자동화 최신 동향
인공지능
고객이 어디서나 AI 워크로드를 실행할 수 있도록 지원하는 플랫폼 업데이트
오픈 하이브리드 클라우드
하이브리드 클라우드로 더욱 유연한 미래를 구축하는 방법을 알아보세요
보안
환경과 기술 전반에 걸쳐 리스크를 감소하는 방법에 대한 최신 정보
엣지 컴퓨팅
엣지에서의 운영을 단순화하는 플랫폼 업데이트
인프라
세계적으로 인정받은 기업용 Linux 플랫폼에 대한 최신 정보
애플리케이션
복잡한 애플리케이션에 대한 솔루션 더 보기
오리지널 쇼
엔터프라이즈 기술 분야의 제작자와 리더가 전하는 흥미로운 스토리
제품
- Red Hat Enterprise Linux
- Red Hat OpenShift Enterprise
- Red Hat Ansible Automation Platform
- 클라우드 서비스
- 모든 제품 보기
툴
체험, 구매 & 영업
커뮤니케이션
Red Hat 소개
Red Hat은 Linux, 클라우드, 컨테이너, 쿠버네티스 등을 포함한 글로벌 엔터프라이즈 오픈소스 솔루션 공급업체입니다. Red Hat은 코어 데이터센터에서 네트워크 엣지에 이르기까지 다양한 플랫폼과 환경에서 기업의 업무 편의성을 높여 주는 강화된 기능의 솔루션을 제공합니다.