Linux Samba directory service build and Java Client access

Source: Internet
Author: User

Objective:

This article is relatively brief, just for quick start, to learn more, recommend an article: http://www.cnblogs.com/mchina/archive/2012/12/18/2816717.html

1, install Samba (the default installation on most Linux may not be complete, it is recommended to reinstall)

#检测是否安装, please note that different installation package protocol commands are not the same #
Rpm-qa|grep Samba
#安装 #
Yum Install Samba samba-client Samba-swat

2. Start the Samba SMB service

/ETC/INIT.D/SMB start

Start Samba NMB Service

/ETC/INIT.D/NMB start

3, add users and Groups

Groupadd dmpuseradd-g DMP FF

/**-Password is best to use case + special characters + numbers, otherwise you will need to repeatedly re-enter **/

passwd FF

4. Restart Samba Service

/ETC/INIT.D/SMB RESTART/ETC/INIT.D/NMB Restart

5, configure/etc/samba/smb.conf Add public directory.

[starfish] #相对目录,= Starfishpath= = = = = 0777= 0777= 0777= 0777== yes

Note: If the condition allows to give the directory as large as possible permissions, the relevant specific parameters please refer to the official documentation.

6. Restart Samba Service

/ETC/INIT.D/SMB RESTART/ETC/INIT.D/NMB Restart

7, perform the directory permission setting under root permissions

chmod 777/home/ff/starfish_cookie_file

8, Faster command

#查看samba服务状态 # #service SMB status#service NMB status# turn on Samba services #service SMB start  #关闭samba服务 #service SMB stop# Restart Samba service #service SMB restart

9,java code access.

 PackageOrg.wit.ff.io;Importjava.net.MalformedURLException;Importjcifs.smb.NtlmPasswordAuthentication;Importjcifs.smb.SmbException;ImportJcifs.smb.SmbFile;Importorg.junit.Test;/*** * <pre> * Java Access Samba sample * </pre> * *@authorF.fang *@version$Id: Sambademo.java, v 0.1 September 29, 2014 AM 2:45:29 f.fang Exp $*/ Public classSambademo {/*** * <pre> * not recommended.     * Cause: If the ' @ ' symbol exists in the username or password, the connection exception is thrown and the samba access path is incorrect. * </pre> * *@throwsmalformedurlexception *@throwssmbexception*/@Test Public voidDemo1 ()throwsmalformedurlexception, smbexception {String constr= "Smb://tomcat:[email protected]/starfish"; Smbfile Smbfile=NewSmbfile (CONSTR); if(Smbfile.exists ()) {//System.out.println ("Hello world!"); }    }    /*** * <pre> * recommended.     * User name and password are passed in independently. * </pre> * *@throwssmbexception *@throwsmalformedurlexception*/@Test Public voidDemo2 ()throwssmbexception, malformedurlexception {String URL= "Smb://@192.168.21.126/starfish"; Ntlmpasswordauthentication Authentication=NewNtlmpasswordauthentication (".", "Tomcat", "1234567"); Smbfile Smbfile=Newsmbfile (URL, authentication); if(Smbfile.exists ()) {//System.out.println ("Hello world!"); }    }}

The Java client accesses Maven dependencies

<Dependency>     <groupId>Jcifs</groupId>     <Artifactid>Jcifs</Artifactid>     <version>1.3.17</version>
</Dependency>

Linux Samba directory service build and Java Client access

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.