Article Title: quickly build a Samba server. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.
1. Check and install the Samba Service
(1). Check whether the Samba service package is installed:
Rpm-qa | grep samba
(2) If not, insert the first installation disk and execute:
Mount/mnt/cdrom
Cd/cdrom/Redhat/RPMS
(3) install the Samba file after entering the directory:
Note: running Samba requires at least three files:
Samba-common-2.2.7a-7.9.0.i386.rpm // files required by both the server and client
Samba-2.2.7a-7.9.0.i386.rpm // server files
Samba-client-2.27a-7.9.0.i386.rpm // client file
Install the preceding three files.
Rpm-ivh samba-common-2.2.7a-7.9.0.i386.rpm // the other two are omitted without writing
(4) After the installation is complete, the optical drive will pop up:
Cd; eject
2. Set the password file.
(1). This setting is used to import system users (/etc/passwd) in Linux to the samba password file.
(/Etc/samba/smbpasswd)
Cat/etc/passwd | mksmbpasswd. sh>/etc/samba/smbpasswd
(2). Next, set access permissions for files and folders such as smbpasswd.
Chown root. root/etc/samba/smbpasswd
Chmod 600/etc/samba/smbpasswd
Chmod 600/etc/samba
Check it out:
Ll-d samba
(3) If you want to manually add a user, you must first ensure that the user exists in Linux. steps:
Useradd liu
Passwd liu
Smbpasswd-a liu // This step adds a Samba user
3. Configure the/etc/samba/smb. conf file.
Although there are a large number of files, there are not many changes to the file, which are generally configured as needed:
(1). Modify [global] (global configuration parameters)
Workgroup = workgroup // workgroup name
Server string = samba server % v at % h // set server name. % v to version number, and % h to run
Host Name of the smb service
Host allow = 192.168.80. 192.168.70. // The host that allows access to the server
Client code page = 939 // supports sharing names in simplified Chinese
The above four items are important. Other configurations can be modified as needed.
(2). Create a shared folder.
Because users have multiple permissions (read, write, and execute) and multiple visitors (users and groups), there are multiple access methods for creating shared resources, the following are examples:
Example 1: create a resource so that all users logging on to the server have the right to use the space (including read and write)
<1>. Edit the smb. conf file.
Vi smb. conf
[Resource]
Comment = local resource
Path =/var/samba/resource
Read only = no
Public = yes // allow access by the guest user
<2>. Create a shared folder
Mkdir-p/var/samba/resource
<3>. Anyone can use this folder, so you have to set the access permission for this folder.
Chmod 707/var/samba/resource
<4>. If you want to place pre-shared files in this folder
Time from cp in another folder, you can use pointer.
For example, to share files in/usr/share/doc, you can:
Ln-s/usr/share/doc/var/samba/resource/doc
Enter/var/samba/resource ls. Is there a pointer file!
Example 2: create a resource to allow user liu full access.
<1>. Edit the smb. conf file.
Vi smb. conf
[Liu]
Comment = liu
Path =/var/samba/liu
Vaild users = smz // only allow liu to access
Public = no
Writable = yes
<2>. Create a shared folder
Mkdir-p/var/samba/liu
<3>. Because only liu can be used, you must set the access permission for this folder.
Chown liu. liu/var/samba/liu
Chmod 700/var/samba/liu
The folder belongs to the liu user and can only be accessed by the liu user.
Example 3: create a resource that can only be accessed by root, zhang, and wang.
<1>. Edit the smb. conf file.
Vi smb. conf
[Zhang wang]
Comment = zhang wang
Path =/var/samba/liu
Vaild users = zhang wang
Public = no
Writable = yes
Creat mask = 0707
<2>. Create a shared folder
Mkdir-p/var/samba/zhangwang
<3>. Set the access permission for the folder.
Chmod 707/var/samba/zhangwang
The folder can only be accessed by root, zhang, and wang.
Example 4: create a resource to allow users in the specified group group2.
<1>. Edit the smb. conf file.
Vi smb. conf
[Group]
Comment = group2
Path =/var/samba/group2
Public = yes
Writable = yes
Write list = @ group2 // set the read/write access user list
<2>. Create a shared folder
Mkdir-p/var/samba/group2
<3>. Set the access permission for the folder.
Chown group2.group2/var/samba/group2
Chmod 770/var/samba/group2
This folder can only be accessed by users in group2.
(3). Create a shared folder and create a shared printer.
<1> there are many ways to configure the printer. For example, you can call up the configuration by using the redhat-config-printer command.
Menu.
<2>. Of course, you must also set smb. conf:
[Global]
Printcap name =/etc/printcap // configuration file path
[Printers]
Writable = no
Guest OK = yes // guest available
Browseable = no // cannot be viewed
Ptrintable = yes
Path =/var/spool/samba // queue location
Printer admin = root // printer Administrator
Other configurations remain unchanged or as needed
Next, add the print driver settings:
[Print $]
Comment = printer drivers
Path =/etc/samba/drivers
Browseable = yes
Guest OK = no
Read only = yes
Write list = root
Create the drivers folder: mkdir-p/etc/samba/drivers
Finally, prepare the printer driver for the user and start the Print Sharing:
Cupsaddsmb-a-U root //-a is used to share all printers.-U is run as root.
Cupsaddsmb command
4. test and start the Samba server.
Testparm // Test
Service smb start
Pstree | grep mbd // check whether the instance is started
5. Access Samba
(1). Access from Windows.
Use "Network neighbors" to access the service.
(2) You can use an IP address or a host name for access.
Vi/etc/samba/lmhosts
192.168.80.35 smz_f91 // create a ing between the host name and IP address
Use the smbclient command during access as follows:
Smbclient-l ip/host name [-U user name] // browse Linux/Windows resource list
Smbclient-L 192.168.80.35 // browse Linux
Smbclient-L 192.168.80.45-U administrator // Browse Windows
Smbclient // IP/Shared Folder name-U System User Name // view the content of a shared resource in detail
Smbclient // 192.168.80.45/123-U root/administrator // as root or administrator
Login 45 host access Shared Folder 123
So far, the simple creation of the Samba server has ended.