|
Linux configuration Samba server
1, what is samba
Samba services similar to the Windows share function, you can share files on Linux, windows access, of course, can also be accessed on Linux.
Is a LAN in the sharing of documents and printers, a communication protocol, which for the LAN between the different computers to provide documents and printers and other resources sharing services.
2, the installation configuration samba
Install the command: yum install -y samba samba-client
Configuration file: /etc/samba/smb.conf
[Global]
Workgroup = MYGROUP
Server string = Samba Server Version% v
Security = user
Passdb backend = tdbsam
Load printers = yes
Cups options = raw
Configuration file explanation:
[Global] definition of the overall configuration, workgroup used to define the working group, I believe that if you installed the windows system, you will not unfamiliar to this workgroup. Under normal circumstances, we need to change here MYGROUP WORKGROUP (windows default workgroup name).
Security = user # This specifies the security level of samba.
There are four levels of security:
Share: Users do not need an account and password to log in to the samba server
User: samba server by the service responsible for checking the account and password (default)
Server: check account and password work by another windows or samba server
Domain: Specifies the Windows domain control server to authenticate the user's account and password.
Passdb backend = tdbsam #passdb backend (user background)
There are three user samba background: smbpasswd, tdbsam and ldapsam.
Load printers: Load the printers
Cups options = raw printer-related settings;
3, samba configuration related commands
Smbpasswd: smbpasswd smbpasswd smbpasswd tool to use the system to the user (real user or virtual user) to set a Samba password, the client will use this password to access Samba resources. Smbpasswd In / etc / samba, it is sometimes necessary to create the file manually.
Tdbsam: Use the database file to create the user database. The database file is called passdb.tdb, in / etc / samba. Passdb.tdb User database Samba users can be created using smbpasswd -a. The Samba user to be created must be a system user. You can also create a Samba account using pdbedit.
There are a number of pdbedit parameters that list several major ones:
Pdbedit-a username: Create a new Samba account.
Pdbedit -x username: Delete the Samba account.
Pdbedit -L: lists the Samba user list, read passdb.tdb database file.
Pdbedit -Lv: Lists the Samba user list details.
Pdbedit -c "[D]" -u username: Suspend the Samba user account.
Pdbedit -c "[]" -u username: Restore the Samba user account.
Ldapsam: Authenticates users based on LDAP account management. First of all to establish LDAP service, set "passdb backend = ldapsam: ldap: / / LDAP Server"
Load printers and cups options two parameters used to set the printer-related.
In addition to these parameters, there are several parameters you need to know:
Netbios name = MYSERVER # Set the host names that appear in My Network Places
Allow = 127. 192.168.12. 192.168.13. 172.16. # Is used to set the allowable host, if in front of the ";" means that all hosts
Log file = /var/log/samba/%m.log # Samba log definition, where the% m is above the netbios name
Max log size = 50 # Specify the maximum log size, in K units
[Homes] The contents of the share of the user's own home directory, that is, when the user logs on to the samba server is actually into the user's home directory, the user login, the share name is not homes but the user's own identity For a simple file-sharing environment, this part can be watched out.
[Printers] This section sets up printer sharing.
4, samba practice one
Requires a shared directory, anyone can access, that is, do not have to enter a password to access, require read-only;
[Global] Section MYGROUP changed to WORKGROUP
Security = user to security = share
At the end, add:
[Share]
Comment = share all
Path = / tmp / samba
Browseable = yes
Public = yes
Writable = no
Start smb services; smb listening port for the 139 and 445;
[Root @ pma ~] # /etc/init.d/smb start
[Root @ pma ~] # netstat -nlp | grep smb
Tcp 0 0 0.0.0.0:139 0.0.0.0:* LISTEN 1329 / smbd
Tcp 0 0 0.0.0.0:445 0.0.0.0:* LISTEN 1329 / smbd
Tcp 0 0 ::: 139 ::: * LISTEN 1329 / smbd
Tcp 0 0 ::: 445 ::: * LISTEN 1329 / smbd
Mkdir / tmp / samba
Chmod 777 / tmp / samba
Touch / tmp / samba / sharefile
Echo "111111"> / tmp / samba / sharefile
Start: /etc/init.d/smb start
Check the configuration smb.conf is correct testparm
Test: windows machine browser input file: //192.168.22.30/share
Or run the bar enter: \\ 192.168.22.30 or \\ 192.168.22.30 \ share
5, Samba practice II
Share a directory, use the user name and password before you can log in, you can read and write requirements;
[Global] section contains the following:
[Global]
Workgroup = WORKGROUP
Server string = Samba Server Version% v
Security = user
Passdb backend = tdbsam
Load printers = yes
Cups options = raw
Need to join:
[Myshare]
Comment = share for users
Path = / samba
Browseable = yes
Writable = yes
Public = no
Create the directory: mkdir / samba
Modify permissions: chmod 777 / samba
Create a system account:
Useradd user1
Useradd user2
Add user1 / user2 to the samba account:
Pdbedit -a user1 # need to enter the user password 2 times
Pdbedit -a user2
List all samba accounts: pdbedit -L
Restart the service service smb restart
Test: Browser input file: //192.168.22.30/myshare
Run the input: \\ 192.168.22.30 or \\ 192.168.22.30 \ myshare
Enter \\ 192.168.22.30 pop-up dialog box, you need to enter user1 user name and password, log in, in addition to myshare shared folder, there are user1 user home directory; user1 has read and write permissions on the directory;
[Root @ abctest samba] # pdbedit -a user1
New password:
Retype new password:
Unix username: user1
NT username:
Account Flags: [U]
User SID: S-1-5-21-4158901286-2295312163-1106066968-1000
Primary Group SID: S-1-5-21-4158901286-2295312163-1106066968-513
Full Name:
Home Directory: \\ abctest \ user1
HomeDir Drive:
Logon Script:
Profile Path: \\ abctest \ user1 \ profile
Domain: abctest
Account desc:
Workstations:
Munged dial:
Logon time: 0
Logoff time: never
Kickoff time: never
Password last set: 1, 25 May 2015 01:39:08 CST
Password can change: 1, 25 May 2015 01:39:08 CST
Password must change: never
Last bad password: 0
Bad password count: 0
Logon hours: FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
12 [root @ abctest samba] # pdbedit -L
User1: 502:
Experimental testing, pause the user, restore the user, delete the user;
Samba server, the first suspension of users, accounts marked as [DU], the normal state [U]; Client access, suggesting that the account is not available;
[Root @ abctest samba] # pdbedit -c [D] -u user1
Unix username: user1
NT username:
Account Flags: [DU]
[Root @ localhost mnt] # smbclient //192.168.22.30/myshare -Uuser1
Enter user1's password:
Session setup failed: NT_STATUS_ACCOUNT_DISABLED
Samba server to restore the user, account marked [U]; client access, back to normal;
[Root @ abctest samba] # pdbedit -c [] -u user1
Unix username: user1
NT username:
Account Flags: [U]
[Root @ localhost /] # smbclient //192.168.22.30/myshare -Uuser1
Enter user1's password:
Domain = [WORKGROUP] OS = [Unix] Server = [Samba 3.6.23-14.el6_6]
Smb: \>
Samba server to delete the user, the client access, the error account is not available;
[Root @ abctest samba] # pdbedit -x user1
[Root @ localhost /] # smbclient //192.168.22.30/myshare -Uuser1
Enter user1's password:
Session setup failed: NT_STATUS_ACCOUNT_DISABLED
6, Linux access to shared files samba
Install the client software yum install -y samba-client
Command format: smbclient // IP / share name-U user name
Such as: smbclient //127.0.0.1/share If anonymous access can be omitted-U
Mount mount samba directory: mount-t cifs //192.168.0.22/myshare / mnt -o username = user1, password = 123456 login with the user password;
Mount-t cifs //192.168.0.22/myshare / mnt Anonymous access does not require the -o parameter;
Such as the implementation of the suggested parameters wrong, but also need to install cifs-utils package;
Linux client test samba share:
Enter the wrong password, login error LOGON_FAILURE; enter the correct password to enter, put upload the file, get download file; upload file smb server to view the owner, group user1; user1 in the shared folder to create a new directory, delete the file ; Help can list the current command line can execute the command;
[Root @ localhost ~] # smbclient //192.168.22.30/myshare -Uuser1
Enter user1's password:
Session setup failed: NT_STATUS_LOGON_FAILURE
[Root @ localhost ~] # smbclient //192.168.22.30/myshare -Uuser1
Enter user1's password:
Domain = [WORKGROUP] OS = [Unix] Server = [Samba 3.6.23-14.el6_6]
Smb: \> ls
. D 0 Mon May 25 01:55:23 2015
... DR 0 Mon May 25 01:35:52 2015
Sa D 0 Mon May 25 01:55:17 2015
A11.txt A 0 Mon May 25 02:00:32 2015
35727 blocks of size 524288. 28572 blocks available
Smb: \> put 1.sql
Putting file 1.sql as \ 1.sql (180.8 kb / s) (average 180.8 kb / s)
Smb: \> get a11.txt
Getting file \ a11.txt of size 0 as a11.txt (0.0 KiloBytes / sec) (average 0.0 KiloBytes / sec)
Smb: \> ls
. D 0 Mon May 25 01:55:23 2015
... DR 0 Mon May 25 01:35:52 2015
Sa D 0 Mon May 25 01:55:17 2015
1.sql A 1851 Mon May 25 02:02:19 2015
A11.txt A 0 Mon May 25 02:00:32 2015
35727 blocks of size 524288. 28572 blocks available
Smb: \> help
? Allinfo altname archive blocksize
Cancel case_sensitive cd chmod chown
Close del dir du echo
Exit get getfacl geteas hardlink
Help history iosize lcd link
Lock lowercase ls l mask
Md mget mkdir more mput
Newer open posix posix_encrypt posix_open
Posix_mkdir posix_rmdir posix_unlink print prompt
Put pwd q queue quit
Readlink rd recurse reget rename
Reput rm rmdir showacls setea
Setmode stat symlink tar tarmode
Timeout translate unlock volume vuid
Wdel logon listconnect showconnect ..
Smb: \> exit
[Root @ abctest samba] # ls -l
-rwxr - r-- 1 user1 user1 1851 May 25 02:02 1.sql
Client mount mount samba shared folder to the local:
[Root @ localhost ~] # mount-t cifs //192.168.22.30/myshare / mnt -o username = user1, password = 123456
[Root @ localhost ~] # mount
/ Dev / sdb3 on / type ext4 (rw)
Proc on / proc type proc (rw)
Sysfs on / sys type sysfs (rw)
Devpts on / dev / pts type devpts (rw, gid = 5, mode = 620)
Tmpfs on / dev / shm type tmpfs (rw)
/ Dev / sdb1 on / boot type ext4 (rw)
None on / proc / sys / fs / binfmt_misc type binfmt_misc (rw)
//192.168.22.30/myshare on / mnt type cifs (rw) |
|
|
|