Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Samba deployment and optimization

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

Some network administrators may use this service more frequently, because the samba service allows us to share a directory on the linux machine, and then let the windows machine access it; it is as convenient as file sharing between windows and windows; it can also configure some user login rights.

Server side

# # installation

[root@wy ~] # yum install-y samba samba-client

Explanation:

Samba server

Samba-client client

# # viewing configuration files

[root@wy ~] # vim / etc/samba/smb.conf

Explanation:

[global] Global Settin

Workgroup = MYGROUP working group

Server string = Samba Server Version% v displayed information (custom)

Security = user security level

User: need to be verified by user name and password before you can log in to our samba shared file

Shell: if anonymous users, do not need users, do not need authentication to directly access shared files, the most insecure

Server: checking accounts and passwords, that is, authentication is done by another server, which is done by a remote console

Domain: this involves the domain controller in windows, which can verify the user's account and password through the domain controller.

Passdb backend = how the user name and password are stored in tdbsam. Default is tdbsam, and the other two are smbpasswd and ldapsam

Smbpasswd is a user who uses a tool smbpasswd to go to the operating system, mapping the user of the system into a virtual user.

Then we set a password for samba.

Tdbsam is similar to smbpasswd, but there are differences (such as the way passwords are stored); tdbsam is more secure

Ldapsam authenticates users based on ldap account management, and needs the help of our ldap service

Load printers = yes cups options = raw these two are about printer settings

[homes] this module is about whether your user's home directory can be shared.

[printers] this module is related to the printer

Do an experiment, the requirement: share a directory out, anyone can access the directory, do not need to enter a user name and password to access, just like ftp anonymous login, but the requirement is read-only, can not write

# # Editing configuration File

[root@wy ~] # vim / etc/samba/smb.conf

Security = share

Workgroup = WORKGROUP / / because windows is workgroup

* add at the end of the file

[wyy]

Comment = share all / / Custom description

Path = / tmp/sambadir / / shared directory

Browseable = yes / / whether it is allowed in our working group

Public = whether yes / / is public or not

Writable = no / / not writable

# # start the service

[root@wy ~] # / etc/init.d/smb start

Start the SMB service: [OK]

# # create a shared directory first

[root@wy ~] # mkdir / tmp/sambadir

[root@wy ~] # cp / etc/passwd / tmp/sambadir/1.txt

# # create a directory under a shared directory to verify whether it is not writable (non-writable is configured in the configuration file)

[root@wy ~] # mkdir / tmp/sambadir/test

[root@wy ~] # chmod 777! $

Chmod 777 / tmp/sambadir/test

Access under windows

# # opening the Operation of windows

# # see the name created in the configuration file

# # View the following directory file

# # verify that it is not writable

Access under linux

# # Login in the first way

[root@wy ~] # smbclient / / 192.168.219.129/wyy

WARNING: The security=share option is deprecated

Enter root's password:

Domain= [WORKGROUP] OS= [Unix] Server= [Samba 3.6.23-36.el6_8]

Server not using user level security and no password supplied.

Smb:\ > ls

. D 0 Wed Nov 16 22:06:20 2016

.. D 0 Wed Nov 16 22:05:41 2016

Test D 0 Wed Nov 16 22:06:20 2016

1.txt 1383 Wed Nov 16 22:06:05 2016

35418 blocks of size 524288. 25862 blocks available

Explanation:

Without entering the password, you can enter the car directly.

# # mounting in the second way

# # install related to mount first

[root@wy ~] # yum install-y cifs-utils

# # mounting

[root@wy] # mount-t cifs / / 192.168.219.129/wyy / opt

Password:

Explanation:

You don't have to enter the password, just enter.

# # View Mount

[root@wy] # df-h

Filesystem Size Used Avail Use% Mounted on

/ dev/mapper/vg_wy-lv_root 18G 3.8G 13G 24% /

Tmpfs 495m 0 495m 0% / dev/shm

/ dev/sda1 485M 34M 426M 8% / boot

/ / 192.168.219.129/wyy 18G 3.8G 13G 24% / opt

# # viewing shared Directory

[root@wy ~] # cd / opt/

[root@wy opt] # ls

1.txt test

# # verify whether the directory under it is unwritable

[root@wy opt] # cd test/

[root@wy test] # vim a.txt

Tip:

"a.txt"

"a.txt" E212: unable to open and write file

Please press ENTER or other command to continue

Summary: this is without a user name and password, so what to do with a user name and password? Please see the next section.

Requirements: need to enter a user name and password to access the shared directory, and can read and write

# # Editing configuration File

[root@wy ~] # vim / etc/samba/smb.conf

Security = user

* at the end of the file

[wyylinux]

Comment = share for users

Path = / tmp/sambadir

Browseable = yes

Writable = yes

Public = no

# # creating a Test account

[root@wy ~] # useradd smbuser1

Explanation:

Its password does not need to be defined, because we do not log in to the samba service with the system user name and password, but it is important to understand that this samba service logs in with the same user name as the system user name, but in fact, our smbuser1 is only a mapping, it is only a mapping of the system user.

# # adding users to pdbedit tools

[root@wy] # pdbedit-a smbuser1

New password:

Retype new password:

Explanation:

-an is add.

-x is to delete

-h to see what options are available for this tool

# # restart the service

[root@wy ~] # / etc/init.d/smb restart

Access under windows

# # Open and run

# # enter the test account and password after entering enter

# # you can see the name of the shared directory module

# # you can create files under a shared directory

# # choose encoding when saving, otherwise it will be garbled under linux

Access under linux

# # Login in the first way

[root@wy ~] # smbclient / / 192.168.219.129/wyylinux

Enter root's password:

Session setup failed: NT_STATUS_LOGON_FAILURE

[root@wy ~] # smbclient-Usmbuser1 / / 192.168.219.129/wyylinux

Enter smbuser1's password:

Domain= [WORKGROUP] OS= [Unix] Server= [Samba 3.6.23-36.el6_8]

Smb:\ > ls

. D 0 Wed Nov 16 22:06:20 2016

.. D 0 Wed Nov 16 22:18:45 2016

Test D 0 Wed Nov 16 22:06:20 2016

1.txt 1383 Wed Nov 16 22:06:05 2016

35418 blocks of size 524288. 25857 blocks available

Explanation:

You need to specify a user name with-U when you log in

# # mounting in the second way

# # mounting

[root@wy] # mount-t cifs-o username=smbuser1,password=123456 / / 192.168.219.129/wyylinux / opt

# # View Mount

[root@wy] # df-h

Filesystem Size Used Avail Use% Mounted on

/ dev/mapper/vg_wy-lv_root 18G 3.8G 13G 24% /

Tmpfs 495m 0 495m 0% / dev/shm

/ dev/sda1 485M 34M 426M 8% / boot

/ / 192.168.219.129/wyy 18G 3.8G 13G 24% / opt

/ / 192.168.219.129/wyylinux 18G 3.8G 13G 24% / opt

# # Mount again before uninstalling

[root@wy ~] # umount / opt

[root@wy ~] # umount / opt

[root@wy] # df-h

Filesystem Size Used Avail Use% Mounted on

/ dev/mapper/vg_wy-lv_root 18G 3.8G 13G 24% /

Tmpfs 495m 0 495m 0% / dev/shm

/ dev/sda1 485M 34M 426M 8% / boot

[root@wy] # mount-t cifs-o username=smbuser1,password=123456 / / 192.168.219.129/wyylinux / opt

[root@wy] # df-h

Filesystem Size Used Avail Use% Mounted on

/ dev/mapper/vg_wy-lv_root 18G 3.8G 13G 24% /

Tmpfs 495m 0 495m 0% / dev/shm

/ dev/sda1 485M 34M 426M 8% / boot

/ / 192.168.219.129/wyylinux 18G 3.8G 13G 24% / opt

# # go to the shared directory and test whether a new file can be created

[root@wy ~] # cd / opt/

[root@wy opt] # ls

1.txt test

[root@wy opt] # cd test/

[root@wy test] # ls

2222.txt

[root@wy test] # touch 12.txt

[root@wy test] # ls

12.txt 2222.txt

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report