How to Access Linux Directory or Files from Windows

Many times you want to share Linux directories and file and access them from Windows such that you can modify from Windows and that modifications should be reflected directly to the Linux. Samba is the most popular interoperability tool between Windows and Linux. This is a step by step guide to configure samba on Linux.

1. Install samba on Linux.
First of all you have to make sure that samba is installed on the Linux computer. If your Linux is RedHat based then you can use yum command to check whether samba is installed.

yum info samba

If it is not already installed then issue this command as root.

yum install -y samba

2. Add samba user
Now you have to register an existing Linux user, say user2, to the samba repository.

smbpasswd -a user2

you have to set a password for this user, say, pass123.

3. Setting of samba config file.
You have to make sure that few settings of the samba config file is ok. Open the /etc/samba/smb.conf file. This file has many sections. Go the section “Standalone Server Options” and check these two lines are not commented.
samba configuration1

Now make sure the home directory of user2 has the access permission. Go to the “Share Definitions” section and make sure the configuration is something like this.
samba configuration2

4. Restart the smb service.
If you changed something in the /etc/samba/smb.conf file, you have to restart the smb service to get the changes applied.

 
service smb restart
service nmb restart

5. Access the home directory of user2 from windows.
Open the windows explorer. Type the ip address of the Linux computer in the address bar of the explorer. Enter the user name user2 and password pass123 (set for user2 in step 2). Now You should see a folder called user2. This is basically the home directory of the Linux user user2.
samba configuration3

6. Add something to the share directory.
Double-click of user2 directory to go inside the folder. Create a test file, say, sample.txt. Open this file in any editor of Windows and write something. Save the file.

7. Check this modification on Linux.
Login as user2 on the Linux computer. You should see the file sample.txt in the home directory. If you open the file on Linux, you will whatever you wrote on Windows.

Now if you want to share folder outside the home directory of user2, follow these steps.

8. Create a folder you want to share
Next step is to create the directory you want to share. You can share existing directory too. Create directory sampledirectory. Give read write permission to this folder. Create an empty file, samplefile, inside the sampledirectory.

mkdir /sampledirectory
chmod 770 /sampledirectory
cd /sampledirectory
touch samplefile
cd -

9. Add a Linux user group. You can work with an existing group also. Then you have to skip this step.

groupadd sambausers

10. Give ownership of the folder to this group.

chown :sambausers /samplefolder

11. Add an existing Linux user to the sambausers group.

usermod -G sambausers user2

12. Open the /etc/samba/smb.conf file and add the following lines in “Share Definitions” section. Add the section shown below.
samba configuration4

13. Now access the Linux computer as step 5. You will see a share folder called “sample“. If you go inside the folder you will see all contents (files and folders) of the sampleditectory. You can modify the samplefile that was created inside the sampledirectory on Linux. If you go inside the Linux computer you will see the modifications.

Author: Srikanta

I write here to help the readers learn and understand computer programing, algorithms, networking, OS concepts etc. in a simple way. I have 20 years of working experience in computer networking and industrial automation.


If you also want to contribute, click here.

Leave a Reply

Your email address will not be published. Required fields are marked *

0
0
0
0
0
0