Linux SMB and NFS file sharing

Source: Internet
Author: User

One, SMB file sharing

1. Installing and adding users to SMB1.1 Installing the SMB software
Yum Install Samba Samba-common samba-client-ysystemctl start SMB nmbsystemctl enable SMB NMB
1.2 Adding users to SMB
SMB user must be local user smbpasswd-a studentnew SMB password: #输入smb当前用户密码Retype new SMB Password: #确认密码 pdbedit-l #查看s MB User Information pdbedit-x SMB user #删除smb用户


1.3 Viewing the shared directory for SMB

View your own shared directory, add directory after default share home directory

[[Email protected] ~]# smbclient  -l //172.25.254.231 -u studententer  student ' s password:domain=[mygroup] os=[windows 6.1]server=[samba 4.2.3]           Sharename       Type      Comment         ---------        ----     -------          IPC$            IPC   ipc service  (samba server version 4.2.3)           student         Disk   Home  directoriesdomain=[mygroup] os=[windows 6.1]server=[samba 4.2.3]            server              comment          ---------             -------          Workgroup             Master          ---------            -------
[[Email protected] ~]# smbclient //172.25.254.231/student  -u studententer  student ' s password:domain=[mygroup] os=[windows 6.1]server=[samba 4.2.3]smb: \ > #此时你如果想看你的共享目录就会出现如下错误, because the selinux  is open smb: \> lsnt_status_access_denied listing  \* #这时你需要将selinux的samba_enable_home_dirs打开. #同时还需要在配置文件中设定smb用户可以访问自己的家目录 # is the 30th row of/etc/samba/smb.conf  setsebool -p samba_enable_home_dirs  on[[email protected] ~] #setsebool   samba_enable_home_dirs on[[email  Protected] ~]# smbclient //172.25.254.231/student  -u studententer student ' S password:domain=[mygroup] os=[windows 6.1]server=[samba 4.2.3]smb: \> ls  .           D         0  THU JUL 10 19:06:52 2014&NBSP, ....   &nbSp;       d        0  thu  Jul 10 18:19:09 2014 .bash_logout     H        18  Wed Jan 29 07:45:18 2014 .bash_profile      h      193  wed jan 29 07:45:18  2014 .bashrc        H       231  wed jan 29 07:45:18 2014 .ssh         dh        0  thu jul 10 18:19:10  2014 .config       DH         0 thu jul 10 19:06:53 2014  10473900 blocks of size  1024. 7318236&nbSp;blocksavailable 
 [[email protected] ~]# vim  /etc/samba/smb.conf 30 setsebool    -p samba_enable_home_dirs on# open to view the user's home directory 49 setsebool  -p samba_ export_all_roon       #只读共享51  setsebool  -p samba_export_all_ rwon      #读写共享 # #在selinux中设定smb用户可以访问自己的家目录89    workgroup =  mygroup# Modify the name of the tag, which is the name of the domai below #[[email protected] ~]# smbclient  -l // 172.25.254.231 -u student#enter student ' S password: #Domain =[mygroup] os=[windows  6.1]server=[samba 4.2.3]96  hosts allow =172.25.254.131# Only to 172.25.254.131 this host, other users will log on the following error: [[email protected] ~]# smbclient  // 172.25.254.231/student  -u studententer student ' S password:protocol negotiation  failed:nt_status_invalid_network_response

3. Basic settings for shared directories

3.1 Simple setup steps for shared directories

Vim/etc/samba/smb.conf[haha] Share Name comment = Description of the shared directory path = absolute path to the shared directory workgroup = Westos When the shared directory is a user-created directory semanage Fcontex T-a-T samba_share_t ' directory name (/.*)? ' RESTORECON-RVVF directory name when the shared directory is set up for the system directory Setsebool-p samba_export_all_ro on #只读共享setsebool-P SAMBA_EXPORT_ALL_RW on # Read/write Sharing

3.2 Instances of shared directories

[[email protected] ~]# vim  /etc/samba/smb.conf#] Below is the code for the added shared directory [Feitian] #共享目录的名称, is what you need to fill in when you mount it: for example//172.25.254.231/feitiancomment = local directory  /westospath =  /westos[[email protected] ~]# systemctl restart smb# When you look at it, you'll have one more shared directory. When you log in, you will find the following error, or because selinux[[email protected] ~]# smbclient -l // 172.25.254.231 -u studentfeitian      disk       local directory /westos[[email protected] westos]# smbclient // 172.25.254.231/feitian  -u studententer student ' s password:         #输入添加的用户student的密码Domain =[MYGROUP] OS=[WINDOWS 6.1]SERVER=[SAMBA 4.2.3]SMB:  \> lsnt_status_access_denied listing \* #修改smb共享目录的安全上下文 [[email protected] ~] # semanage  fcontext -a -t  samba_share_t   '/westos (/.*)? ' [[email protected] ~]# restorecon  -rvvf /westosrestorecon reset / westos contextunconfined_u:object_r:default_t:s0->system_u:object_r:samba_share_t:s0restorecon  reset /westos/file1 contextunconfined_u:object_r:default_t:s0->system_u:object_r:samba_share_t: S0restorecon reset /westos/file2 contextunconfined_u:object_r:default_t:s0->system_u:object_ R:samba_share_t:s0restorecon reset /westos/file3 contextunconfined_u:object_r:default_t:s0-> system_u:object_r:samba_share_t:s0# then you login will be good, do not forget the/etc/samba/smb.conf in the SELinux need to open. Also, enable SELinux read-only or read-write access to the SMB service on the host. [[email protected] ~]# mount//172.25.254.231/student   /mnt  -o  username=student,password=student[[email protected] ~]# df -h |grep//172.25.254.231// 172.25.254.231/student   10g 3.1g  7.0g  31% /mnt# Boot automatically mount Vim /etc/fstab//172.25.254.231/feitian  /mnt  cifs defaults, Username=studnet,password 0  0
configuration parameters for 4.samba 
#匿名用户访问guest  ok = yesmap to guest = bad user  #访问控制hosts   allow =            #仅允许hosts  deny =             #仅拒绝valid  users =            #当前共享的有效用户valid  users = westos      #当前共享的有效用户为westosvalid  users =  @westos      #当前共享的有效用户为westos组valid  users = +westos      #当前共享的有效用户为westos组   #读写控制所有用户均可写chmod  o+ w /mntsetsebool -p samba_export_all_rw onvim /etc/samba/smb.confwritable =  yes  #设定指定用户可写write  list = student      #可写用户write  list =  +student     #可写用户组write  list =  @student         #也是可写用户组admin  users = westos      #共享的超级用户指定 

5.SMB Multi-user sharing

Do the following on the client:

 [[email protected] ~]# vim /root/hahausername=studentpassword=student[[email  Protected] ~]# chmod 600 /root/haha[[email protected] ~]# yum install  cifs-utils -y[[email protected] ~]# cifscreds clear  -u student  172.25.254.231password:        # #smb用户student的密码mount  -o  credentials=/root/haha,multiuser,sec=ntlmssp //172.25.254.231/haha  /mnt/#credentials =/ root/haha     Specifies the user file to use when mounting #multiuser             support multi-user authentication #sec=ntlmssp           authentication mode for standard SMB authentication mode   [[email protected] ~]# df -h|grep 172.25.254.231//172.25.254.231/feitian    10g 3.1g  7.0g  31% /mnt# Shared User cifscreds add -u  westos  172.25.254.100password:         # #smb用户westos的密码ls  /mnt 

Ii. NFS file Sharing

1. Introduction to NFS

NFS is the abbreviation for the network file System, and the main function is to allow different machines to share files or directories with each other through the web, which can be mounted (mount) to mount the NFS server-side shared data file directory to the NFS client locally. There are multiple versions of the NFS protocol: Linux supports version 4, version 3, and version 2, and most system administrators are familiar with NFSv3. By default, the protocol is not secure, but newer versions (such as NFSV4) provide more secure authentication support and can even be encrypted with Kerberos

2. Simple NFS sharing between different hosts

The simple but configured on the server

[Email protected] ~]# Vim/etc/exports/westso/lala 172.25.254.231 (rw,sync) #共享serve/westos/lala this directory, The client has read and write, and the creation of the shared directory is directly written to the host's in-memory #exportfs-RV directly refreshed without restarting the NFS service

In the client's Jane but configuration

[[email protected] ~]# showmount-e 172.25.254.231Export list for 172.25.254.231:/westos/lala 172.25.254.131[[email Protected] ~]# mount-t NFS 172.25.254.231:/westos/mnt[[email protected] ~]# df-h|gerp 172.25.254.231172.25.254.231:/we Stos/lala 9.2G 2.5G 6.3G 29%/mnt

Set the boot automatically mount, here is not said, has said too changeable

3. The default directory is automatically mounted

3.1 Installing the Software

Client Installation software

[[email protected] ~]# yum install autofs-y[[email protected] ~]# systemctl restart Autifs.server[[email protected] ~]# Cd/net[[email protected] ~]# CD 172.25.254.231[[email protected] ~]# ls westos[[email protected] ~]# Cd/westos/lala #这样就可以看到他的共享目录下面的内容, and is automatically mounted, the default 5 minutes after exiting the directory is automatically uninstalled. He can modify the # in/etc/autofs.conf can be modified.

4. Automatic mounting of the specified directory

Modify the configuration file on the client

[[email protected] ~]# vim/etc/auto.master# Add a line,/NFS refers to the first level directory of the shared directory,/etc/auto.nfs He is the master's sub-file/westos/etc/auto.nfs[[ Email protected] ~] #vim The second-level directory of the/etc/auto.nfs# shared directory * 172.25.254.231:/& #这个意思是前面的第二层目录和第一层目录是一致的, if you mount the Lala it means you Auto-mount Directory is/westos/lala


This article is from the "13122323" blog, please be sure to keep this source http://13132323.blog.51cto.com/13122323/1956882

Linux SMB and NFS file sharing

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.