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

Smb server building

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

Share

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

CentOS 6.4install and configure Samba services

Environment description

Samba server system: CentOS 6.4x86x64

Samba server IP:10.1.1.1

Samba client system: CentOS 6.4x86x64

Samba client IP:10.1.1.1

Install the samba server

Step-1: open the appropriate port on the firewall for samba and run the following command:

Iptables-I INPUT-p tcp-- dport 137j ACCEPT

Iptables-I INPUT-p udp-- dport 137j ACCEPT

Iptables-I INPUT-p tcp-- dport 138j ACCEPT

Iptables-I INPUT-p udp-- dport 138j ACCEPT

Iptables-I INPUT-p tcp-- dport 139j ACCEPT

Iptables-I INPUT-p udp-- dport 139j ACCEPT

Iptables-I INPUT-p tcp-- dport 445-j ACCEPT

Iptables-I INPUT-p udp-- dport 445-j ACCEPT

Service iptables save

Service iptables restart

Step-2: configure SELinux to permissive mode, run the following command:

Setenforce 0 # 00:00 takes effect and expires after restart

Vim / etc/selinux/config

Replace SELINUX=enforcing in the above file with SELINUX=permissive or SELINUX=disable

Step-3: install the samba server and run the following command:

Yum install-y samba

Step-4: configure the smb.conf file, run the following command:

Mv / etc/samba/smb.conf / etc/samba/smb.conf.bak

Vi / etc/samba/smb.conf

The contents of the above configuration file are as follows:

[global]

# # WORKGROUP is the workgroup of samba server

Workgroup = WORKGROUP

# # description of samba server

Server string = Samba Server Version% v

# # NetBIOS name of samba server

Netbios name = CentOS.Server

# # client access Log of samba Server

Log file = / var/log/samba/log.%m

# # maximum log size is 50 KB

Max log size = 50

# # using tdbsam to store user information

Passdb backend = tdbsam

# # ensuring security by using user authentication

Security = user

# # Mapping anonymous user access

Map to guest = bad user

Guest account = nobody

[homes]

# # description of shared Directory

Comment = Home Directories

# # valid user, this directory is in the / home directory

Valid users =% S

# # you cannot see this directory in the network share of Windows

Browseable = No

# # this directory is writable

Writable = Yes

[private]

# # description of shared Directory

Comment = Demo Directory

# # shared directory path

Path = / samba/private

# # valid users

Valid users = @ user1

# # you can see this directory in the network share of Windows

Browseable = Yes

# # this directory cannot be accessed publicly anonymously

Public = No

# # this directory is writable

Writable = Yes

[public]

# # description of shared Directory

Comment = Public Stuff

# shared directory path

Path = / samba/public

# # you can see this directory in the network share of Windows

Browseable = Yes

# # this directory can be accessed anonymously

Public = Yes

# # this directory is writable

Writable = Yes

Step-5: set up two user groups and users in the system, user1 and user2, and run the following command:

Groupadd user1

Useradd-g user1 user1

Passwd user1

Groupadd user2

Useradd-g user2 user2

Passwd user2

Note: the password for both user1 and user2 is password.

Step-6: set up two users on the samba server and run the following command:

Smbpasswd-a user1

Smbpasswd-a user2

Note: the samba access password for both user1 and user2 is password.

Step-7: establish the appropriate directory and set access permissions, and run the following command:

Mkdir-p / samba/public

Mkdir-p / samba/private

Chmod-R 777 / samba

Step-8: configure and start the samba service and run the following command:

Chkconfig smb on

Chkconfig nmb on

Service smb start

Service nmb start

Through the configuration of the above eight steps, the shared directory can be accessed on the client. Both user1 and user2 can access the public directory and have read and write permissions; only user1 can access the private directory and have read and write permissions; the personal directories of user1 and user2 are invisible and can only be accessed through url, and each has read and write permissions.

Install the samba client

Step-1: install the samba client and run the following command:

Yum install-y samba-client

Step-2: connect to the shared directory on the server and run the following command:

# # connecting to the Public Directory

Smbclient / / 10.1.1.1/public-U user1

# # connecting to the personal directory smbclient / / 10.1.1.1/user1-U user1 if the login is successful, the Shell command will become a prompt like this: smb:\ > Step-3: after using it, disconnect and run the following command on the samba command line: quit through the above three steps, the samba client can use samba sharing. Manually mount the samba shared directory

Step-1: Mount the personal directory of user1 to the / samba directory of the samba client, and run the following command:

Mkdir-p / samba

Mount-t cifs / / 192.168.4.211/user1 / samba-o user=user1,password=password,workgroup=WORKGROUP

Step-2: after the personal directory is used up, unmount and run the following command:

Umount / samba

Automatically mount the samba shared directory on boot

Add a mount entry for the shared directory to the fstab file to enable auto-mount on boot, but the subsequent connection to the samba server will always be active. Run the following command:

Mkdir / samba

Vi / etc/fstab

Add the mount entry of the shared directory at the end of the above file, as shown below: / / 10.1.1.1/user1 / samba cifs defaults,username=user1,password=password 00, where the fifth field set to 0 means that the file system of the shared directory does not need to be dumped with the dump command, and the sixth field set to 0 indicates that the file system of the shared directory does not need to be checked with the fsck command. In addition, you can also use the automatic mounter (autofs) to automatically mount network shared directories on demand. When the share is no longer in use and is inactive for a certain period of time, the automounter unmounts the share. Automatically mount samba shared directories on demand

Step-1: to modify the timeout for inactivity, run the following command:

Vi / etc/sysconfig/autofs

In the above file

TIMEOUT=300

Replace with

TIMEOUT=600

That is, the timeout for inactivity is changed from 5 minutes to 10 minutes.

Step-2: establish the parent directory of the shared directory mount point and run the following command:

Mkdir-p / samba Step-3: configure the parent directory of the shared directory mount point and run the following command:

Vi / etc/auto.master

Add a new line at the end of the above file, as follows:

/ samba / etc/auto.samba

Where / samba is the parent directory of the mount point, which is always visible in the system and is monitored by the autofs service to determine whether the mount / creation of a subdirectory mount point is "needed". / etc/auto.samba is a single configuration file that contains a list of subdirectory mount points managed by the autofs service under this parent directory. Step-4: configure the shared directory mount point directory and run the following command:

Vi / etc/auto.samba

The contents of the above file are as follows:

User1-fstype=cifs,username=user1,password=password: / / 10.1.1.1/user1

Where user1 is the subdirectory mount point, which is usually invisible and becomes visible only when it is named / accessed directly after the autofs service creates this directory and mounts the share. Step-5: restart the autofs service and run the following command:

Service autofs restart Step-6: access the network shared directory and run the following command:

Cd / samba/user1

After running the above command, autofs automatically creates the mount point directory and mounts the shared directory. Step-7: uninstall the network shared directory, as shown below:

After all files and directories under / samba/user1 are out of use and the timeout period expires (10 minutes), autofs unmounts the shared directory.

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