"Go" To configure the Samba server under Ubuntu

Source: Internet
Author: User

Original URL: http://my.oschina.net/junn/blog/171388

I. Installation of samba:

sudo apt-get insall samba//(sudo get temp root auth)
sudo apt-get install SMBFS//old version
sudo apt-get install cifs-utils//new version
The above command will install Samba and other related tools. In the older version of Ubuntu, you may need to useSmbfsAlternativecifs-utils
sudo apt-get install Samba-common

two. Create a shared directory:

1, the System user home directory:
Mkdir/home/john/share//If the configured shared directory does not exist then create
chown-r Nobody./home/john/share//Set shared directory attribution to nobody
sudo chmod 777/home/john/share//Set the shared directory property to 777
Description: John for your Ubuntu username; share you can name it as a shared folder.

2, the General directory:
such as creating/mydir/private and/mydir/public directories (attention to permissions issues, otherwise inaccessible)
mkdir-p/mydir/{private,public}
chown-r Nobody.nogroup/mydir
chmod-r 777/mydir

three. Create a Samba configuration file:

1. smb.conf section Configuration Instructions

[Global]
Server string = Samba Server Version%v
Passdb backend = Tdbsam
Cups options = raw
Security = user//authentication mode for user
Map to Guest = Bad user//This is the key, implementation anonymous without interactive input user name and password on it.
Guest account = Guest//anonymous user mapped to guest user

[MyShare]
Comment = My share
Path =/home/public//shared path
browseable = Yes//Can be browsed, the share name can be seen in the Network Neighborhood
Read Only = No//writable
Guest OK = Yes//Allow anonymous access, this also needs to be set, otherwise anonymous unreachable
Valid users = Samba LIUAG guest//valid user and group
Invalid users = liuben//invalid user and group
Read List = Samba//read-only users and groups (if Read Only = No, read-Only users need this setting)
Write list = LIUAG//read-write user and group (if Read only = Yes, read-write user needs to be set up)
Allow hosts = 192.168.100.236//allows access to host list, supports wildcard characters
Deny hosts = 192.168.100.0/24//disable access to host list, support wildcard characters

Example:
[Global]
Workgroup = Workgroup
Server string = Samba server on Ubuntu
NetBIOS name = UBUNTU_SMB
interfaces = 127.0.0.0/8 eth0
Hosts allow = 192.168.1. 192.168.163.192.168.153.
Security = User
Username map =/etc/samba/smbusers
Encrypt passwords = True
Passdb backend = smbpasswd
SMB passwd file =/etc/samba/smbpasswd
Log file =/var/log/samba/log.%m
Max Open files = 1000
Socket options = Tcp_nodelay

; [Homes]
; Comment = home directories
; browseable = No
; writable = yes
; Valid users =%s
; Create mode = 0664

; [Printers]
; printable = Yes
; browseable = No
; Path =/var/spool/samba

[Code]
Comment = Code//comment is a description of the share, which can be any string.
Path =/home/songyd/code
writable = yes
browseable = yes
Available = yes


2. Save the existing configuration file
sudo cp/etc/samba/smb.conf/etc/samba/smb.conf.bak

3. Modify the current configuration file
sudo gedit/etc/samba/smb.conf
Last added in smb.conf

Example one:
[Share]
Path =/home/john/share
Available = yes
browseable = yes
Public = yes
writable = yes
Valid users =myname
Create mask = 0700
Directory Mask =0700
Force user =nobody
Force Group = Nogroup

Description: Valid users = MyName This myname is his own, after the addition of the user name is added this;
In addition, this [share] name can be casually, this is the name that you display when you visit under Windows;
Under Windows \\162.168.160.11\share can access the contents of Linux under the/home/god/code directory;
Where 162.168.160.11 is your Linux IP address, you can view it with ifconfig.

Example two:
[WWW]
Path =/home/test/www
Available = yes
browseable = yes
Public = yes//Allow anonymous users to log in
writable = yes

Note: Public indicates whether the shared resource can be accessed by the visitor account, and this switch is sometimes called guest OK, so there is a guest OK in the configuration file = Yes in fact, and public = yes is the same.

Then change this here and find [global] to change workgroup = Mshome to: (Note that here the workgroup is the workgroup name in the share) code: (If not also can add to)

Workgroup = Workgroup
Display CharSet = UTF-8
Unix CharSet = UTF-8
DOS charset = cp936

The following three lines are intended to prevent the occurrence of garbled Chinese catalogs.

Four. Create a Samba account:

Now to addmynameThis network access account. If you do not currently have this account in your system (you can also use an account that already exists in the system, such as Root,god), then the code:

sudo useradd myname

The above just addsmynameThis system user, but does not give the user to assign the local login password. So this user will only be able to access from remote, cannot log on from native. And Samba's login password may not be the same as the native login password. This you can see the user you added when restarting the machine, but you do not use it to log on the system, because there is no password to give the native login.

sudo touch/etc/samba/smbpasswd
sudosmbpasswd-a myname

(If you use the account in the system directly, here MyName is the account in your system) then will ask you to enter the Samba account password, this password is not used when the power-on login, is you want to access the win share file or the win share file to access your password when you want to fill in.

The command to delete the network user's account change the above to-X as:sudo smbpasswd-x myname

usage of the SMBPASSWD command

Smbpasswd-a increase the user (the user to be added must be a system user)
Smbpasswd-d freezes the user, that is, the user cannot log in
SMBPASSWD-E restores the user, thaws the user, and allows the frozen user to use the
Smbpasswd-n set the user's password to null.
To write null passwords-true in global
Smbpasswd-x Deleting a user


Five. User Account mapping:

Samba's user account information is stored in the smbpasswd file, and the account that can access the Samba server must correspond to a system account with the same name. Based on this, so, for some hacker, as long as the Samba server drops Samba account, it is equal to know the Linux system account number, as long as crack its Samba account password to exploit can attack the Samba server. So we're going to use the User Account mapping feature to solve this problem.

User Account mapping This feature requires an account mapping relationship table that records the relationship between the Samba account and the virtual account, and the client accesses the Samba server using the virtual login.

1) Edit the master profile vi/etc/samba/smb.conf
Add a row of fields under global username map =/etc/samba/smbusers Turn on the User Account mapping feature.

2) Edit Vi/etc/samba/smbusers
The Smbusers file holds the account mapping relationship, which has a fixed drop format:
Samba Account Number = Virtual account (Map account)

MyName = Networkusername

Account MyName is the Samba account (also the Linux system account number) that we set up above, Networkusername is the account name (virtual account number) that is mapped, account number MyName access to the shared directory as long as the input networkusername can be successfully accessed, but actually access to the Samba server is our myname account, which resolves the security issue.

3) Restart Samba services: Service SMBD restart

4) Verification effect
Enter our defined mapping account Networkusername, note that we did not enter the account MyName, the map account networkusername password and myname account, now you can map the account to browse the shared directory.

Six. Restart the Samba server:

sudo testparm Verify the configuration parameters there is no problem if there is a problem in going back to modify

Sudo/etc/init.d/samba Restart(I do not know why, this directory is not this, with this command always error)

Service Samba Restart
Service SMBD Restart

seven. Test:

Smbclient-l//localhost/share or
Smbclient-l \\127.0.0.1-U myname//This is the samba password you just set up.

Eight. Use:

You can enter IP under Windows to use, enter "\ \" + "Ubuntu machine IP or hostname" + "\ \" + "share" in the folder;

My is: \\162.168.160.11\share (share is just smb.conf in the [share]) to enter the first time the user name and password, this is the fourth step you set the user name and password.

Nine. The uninstallation of Samba:

Dpkg-l |grep Samba
Dpkg-l |grep Smbfs
Dpkg-l |grep SMB

Apt-get Remove SAMBA\SMBFS\SMB

Ubuntu12.04samba Server Configuration


System platform: VMware Workstation9.0 + ubuntu12.04

First, troubleshoot Windows and Linux network connectivity issues:
In the VMware Workstation9.0 " settings " option, set the " network "
Network Connections 1 Select the Enable network connection mode:NAT
Network Connections 2 Select the "Enable network connection" mode:bridged Adapter

Start Ubuntu, view IP address: #ifconfig eth0
Note: Your Linux may have two NICs eth0 and eth1, respectively, look at their IP address, one is and your Windows local connection IP address in a network segment (later use this IP address to login to Samba, also mount NFS server IP)

Say something about the configuration of the IP address (with my own computer example):
I am using ADSL dialing the Internet, the IP address of Windows Local connection is automatically obtained, IP is: 192.168.1.45
Check the IP of Linux under eth0:10.0.2.15;ETH1 IP is 192.168.1.42
The eth1 is the IP address of the local connection for Linux, which is the IP address of the Samba server

Shut down the Linux Firewall command: #ufw disable

Note: UFW is a firewall operation command under Linux, and related actions can be used to view command help

Then just ping the Linux IP under Windows, if you can ping, you can continue the following content, if the ping is not able to find the reason

Note: Ubuntu 12.04 has the latest version of the Samba server installed, without installation. If you use a previous version of 12.04, it is best to upgrade the samba,12.04 version by following the steps below without

Uninstalling Samba,smbclient,samba-common
$sudo Apt-get Remove Samba-common
$sudo Apt-get Remove Smbclient
$sudo Apt-get Remove Samba

Install Ubuntu Samba Server:
sudo apt-get install Samba
sudo apt-get install Smbfs

To start the configuration:

Samba configuration file: /etc/samba/smb.conf
You can modify the configuration file to set up Samba sharing and users
If you are not accustomed to using configuration files, you can also use the graphical interface

Install Ubuntu Samba Graphical management interface
#sudo Apt-get Install System-config-samba

Start the Samba graphical management interface
#sudo System-config-samba

You can also choose a menu: System->administration->samba

The configuration method is the same as in RedHat9
Select the directory you want to share set read-write permission settings access to add Samba users

Restart Samba after configuration is complete
#sudo/etc/init.d/smbd Restart

"Go" To configure the Samba server under Ubuntu

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.