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 file sharing of Linux

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

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

Samba can realize file sharing between Linux and Windows, including server software Samba, client software Samba-client, and Samba-common, which is used to provide server and client programs. Most packages are installed by default in CentOS. The Samba server provides two service programs, smbd and nmbd, which perform different functions. Among them, smbd is responsible for providing clients with access to shared resources (directories and files, etc.) in the server, and nmbd is responsible for providing host name resolution based on NetBIOS protocol in order to query the hosts in the Windows network.

Example:

ABC is a website design company, the company has design department, development department, operation and maintenance department and other departments, the company decided to deploy a Samba server to meet the needs of rapid data sharing among various departments.

Shared directory of design department: / ABC/design

Shared directory of development department: / ABC/develop

Shared directory of operation and maintenance department: / ABC/ops

Public shared directory: / ABC/share

There are two users in each directory, the department head has read and write permission, and others only have read permission. Take the operation and maintenance department as an example: the user name of the supervisor is: opsadmin (password and user name are the same), others: ops1 (password and user name are the same). Public shared directory: administrator (password and user name are the same) has read and write access, and everyone else only has read permission.

1 turn off the firewall and Selinux:

[root@localhost ~] # service iptables stop

[root@localhost ~] # vim / etc/selinux/config

SELINUX=disabled

[root@localhost ~] # setenforce 0

2 configure Samba server:

Installer component

[root@localhost ~] # rpm-qa | grep 'samba'

Samba-common-3.6.23-33.el6.i686

Samba-client-3.6.23-33.el6.i686

Samba-winbind-3.6.23-33.el6.i686

Samba4-libs-4.2.10-6.el6_7.i686

Samba-winbind-clients-3.6.23-33.el6.i686

[root@localhost ~] # yum-y install samba

Set up a shared directory and test files

[root@localhost ~] # mkdir-pv / ABC/ {design,develop,ops,share}

[root@localhost ABC] # echo "This is design" > > / ABC/design/de.txt

[root@localhost ABC] # echo "This is develop" > > / ABC/develop/deve.txt

[root@localhost ABC] # echo "This is ops" > > / ABC/ops/ops.txt

[root@localhost ABC] # echo "This is share" > > / ABC/share/share.txt

[root@localhost ABC] # tree / ABC/

/ ABC/

├── design

│ └── de.txt

├── develop

│ └── deve.txt

├── ops

│ └── ops.txt

└── share

└── share.txt

4 directories, 4 files

Establish an account: the Samba server uses an independent shared account database file, in which the account must have a system user with the same name, so that the host can control the read and write permissions of the shared access; but the password of the shared user is extra and can be different from that of the system user.

[root@localhost] # useradd-s / sbin/nologin opsadmin # add system users first

[root@localhost ~] # pdbedit-a-u opsadmin # then add shared users

[root@localhost] # useradd-s / sbin/nologin ops1

[root@localhost] # pdbedit-a-u ops1

[root@localhost] # useradd-s / sbin/nologin administrator

[root@localhost] # pdbedit-a-u administrator

[root@localhost ~] # pdbedit-L # lists all users

Opsadmin:501:

Administrator:503:

Ops1:502:

[root@localhost ~] # pdbedit-x-u vina # Delete a user

[root@localhost ~] # pdbedit-vL ops1 # displays user details

Unix username: ops1

NT username:

Account Flags: [U]

User SID: Smurl 1-5-21-2138872188-2142312678-3225965792-1001

Primary Group SID: Smurl 1-5-21-2138872188-2142312678-3225965792-513

Full Name:

Home Directory:\\ localhost\ ops1

HomeDir Drive:

Logon Script:

Profile Path:\\ localhost\ ops1\ profile

Domain: LOCALHOST

Account desc:

Workstations:

Munged dial:

Logon time: 0

Logoff time: never

Kickoff time: never

Password last set: Tue, 30 May 2017 12:04:49 CST

Password can change: Tue, 30 May 2017 12:04:49 CST

Password must change: never

Last bad password: 0

Bad password count: 0

Logon hours: FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF

Note: the following command is required to change the password:

Smbpasswd username

Modify the configuration file

[root@localhost ABC] # vim / etc/samba/smb.conf

[global]

Security = user

[share]

Path = / ABC/share

Public = yes

Browseable = yes

Read only = yes

Write list = administrator

[ops]

Path = / ABC/ops

Browseable = yes

Public = no

Write list = opsadmin

Valid users = ops1,opsadmin

[root@localhost ABC] # testparm # check the configuration file

[root@localhost ABC] # chmod-R 777 / ABC/ {design,develop,ops,share}

Start the service

[root@localhost ABC] # service smb start

[root@localhost ABC] # service nmb start

After modifying the configuration file, you need to reload the configuration file

[root@localhost ABC] # service smb reload

Attached: detailed description of common parameters of Samba configuration file:

1) security = user | share:

Share: no need to provide a username and password

User: the shared directory can only be accessed by authorized users and verify the correctness of the account and password

2) path = / ABC/ops: the path to the shared directory

3) browseable = no | yes: whether the directory can be browsed. No means to hide the directory.

4) valid users = ops1,opsadmin: the user allowed to access the share

5) invalid users = * *, * *: users who are prohibited from accessing the share

6) write list = ops1: users who are allowed to write to the share

7) public = no | yes: whether anonymous access is allowed, same as guest ok

8) directory mask = 0755: default permissions for uploading directories

9) create mask = 0644: default permissions for uploading files

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

Servers

Wechat

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

12
Report