1:安装所需软件,打开smb,用本机登陆查看
[root@localhost ~]# yum install samba samba-common samba-client -y
[root@localhost ~]# systemctl start smb
[root@localhost ~]# systemctl status smb
smb.service - Samba SMB Daemon
Loaded: loaded (/usr/lib/systemd/system/smb.service; disabled)
Active: active (running) since Mon 2017-08-21 05:58:50 EDT; 1s ago
Main PID: 2480 (smbd)
Status: "smbd: ready to serve connections..."
CGroup: /system.slice/smb.service
├─2480 /usr/sbin/smbd
└─2482 /usr/sbin/smbd
Aug 21 05:58:50 localhost smbd[2480]: [2017/08/21 05:58:50.093740, 0] ../l...y)
Aug 21 05:58:50 localhost smbd[2480]: STATUS=daemon 'smbd' finished startin...ns
Aug 21 05:58:50 localhost systemd[1]: Started Samba SMB Daemon.
Hint: Some lines were ellipsized, use -l to show in full.
[root@localhost ~]# smbclient -L //172.25.254.111
Enter root's password:
Anonymous login successful
Domain=[MYGROUP] OS=[Windows 6.1] Server=[Samba 4.2.3]
Sharename Type Comment
--------- ---- -------
IPC$ IPC IPC Service (Samba Server Version 4.2.3)
Anonymous login successful
Domain=[MYGROUP] OS=[Windows 6.1] Server=[Samba 4.2.3]
Server Comment
--------- -------
Workgroup Master
--------- -------
2:共享某个用户,用student登陆并查看
[root@localhost ~]# pdbedit -L
[root@localhost ~]# pdbedit -a student
new password:
retype new password:
Unix username: student
[root@localhost ~]# pdbedit -L
student:1000:Student User
[root@localhost ~]# smbpasswd -a lee #添加lee
New SMB password:
Retype new SMB password:
Added user lee.
[root@localhost ~]# pdbedit -L #查看共享用户
student:1000:Student User
lee:1001:
[root@localhost ~]# smbpasswd -x lee #删除用户
Deleted user lee.
[root@localhost ~]# pdbedit -L
student:1000:Student User
[root@localhost ~]# smbclient -L //172.25.254.111 -U student
Enter 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 Directories
Domain=[MYGROUP] OS=[Windows 6.1] Server=[Samba 4.2.3]
Server Comment
--------- -------
Workgroup Master
--------- -------
[root@localhost ~]# smbclient //172.25.254.111/student -U student
Enter student's password:
Domain=[MYGROUP] OS=[Windows 6.1] Server=[Samba 4.2.3]
smb: \> ls
NT_STATUS_ACCESS_DENIED listing \*
smb: \> quit
[root@localhost ~]# getenforce
Enforcing
[root@localhost ~]# setenforce 0
[root@localhost ~]# smbclient //172.25.254.111/student -U student
Enter 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
.. 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. 7269980 blocks available
smb: \>
3:用另一台电脑挂载并查看
[root@localhost ~]# mount -o username=student,password=student //172.25.254.111/student /mnt
[root@localhost ~]# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/vda1 10473900 7593244 2880656 73% /
devtmpfs 927072 0 927072 0% /dev
tmpfs 942660 84 942576 1% /dev/shm
tmpfs 942660 17052 925608 2% /run
tmpfs 942660 0 942660 0% /sys/fs/cgroup
/dev/mapper/vg0-vo 483670 2377 451802 1% /home
/dev/loop0 3947824 3947824 0 100% /var/www/html/rhel7.2
//172.25.254.111/student 10473900 3203912 7269988 31% /mnt
[root@localhost ~]# cd /mnt
[root@localhost mnt]# ls
[root@localhost mnt]# ls -a
. .. .bash_logout .bash_profile .bashrc .config .ssh
[root@localhost ~]# umount /mnt ##取消挂载
[root@localhost ~]# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/vda1 10473900 7593244 2880656 73% /
devtmpfs 927072 0 927072 0% /dev
tmpfs 942660 84 942576 1% /dev/shm
tmpfs 942660 17052 925608 2% /run
tmpfs 942660 0 942660 0% /sys/fs/cgroup
/dev/mapper/vg0-vo 483670 2377 451802 1% /home
/dev/loop0 3947824 3947824 0 100% /var/www/html/rhel7.2
4:sebool值的授权
[root@localhost ~]# smbclient //172.25.254.111/student -U student
Enter student's password:
Domain=[MYGROUP] OS=[Windows 6.1] Server=[Samba 4.2.3]
smb: \> ls
NT_STATUS_ACCESS_DENIED listing \*
smb: \> quit
[root@localhost ~]# getsebool -a | grep samba
samba_create_home_dirs --> off
samba_domain_controller --> off
samba_enable_home_dirs --> off
samba_export_all_ro --> off
samba_export_all_rw --> off
samba_portmapper --> off
samba_run_unconfined --> off
samba_share_fusefs --> off
samba_share_nfs --> off
sanlock_use_samba --> off
use_samba_home_dirs --> off
virt_sandbox_use_samba --> off
virt_use_samba --> off
[root@localhost ~]# setsebool -P samba_enable_home_dirs 1
[root@localhost ~]# smbclient //172.25.254.111/student -U student
Enter 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
.. 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. 7261228 blocks available
smb: \>
5:修改student Domain值
[root@localhost ~]# smbclient -L //172.25.254.111 -U student
Enter 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 Directories
Domain=[MYGROUP] OS=[Windows 6.1] Server=[Samba 4.2.3]
Server Comment
--------- -------
Workgroup Master
--------- -------
[root@localhost ~]# vim /etc/samba/smb.conf
[root@localhost ~]# smbclient -L //172.25.254.111 -U student
Enter student's password:
Domain=[WESTOS] 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 Directories
Domain=[WESTOS] OS=[Windows 6.1] Server=[Samba 4.2.3]
Server Comment
--------- -------
Workgroup Master
--------- -------
6:设置黑白名单
[root@localhost ~]# vim /etc/samba/smb.conf
测试172.25.254.111
[root@localhost ~]# smbclient -L //172.25.254.111 -U student
Enter student's password:
Domain=[WESTOS] 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 Directories
Domain=[WESTOS] OS=[Windows 6.1] Server=[Samba 4.2.3]
Server Comment
--------- -------
Workgroup Master
--------- -------
用另一台电脑试
[root@localhost ~]# smbclient -L //172.25.254.111 -U student
Enter student's password:
Domain=[WESTOS] OS=[Windows 6.1] Server=[Samba 4.2.3]
tree connect failed: NT_STATUS_ACCESS_DENIED
共享自己创建的目录
[root@localhost ~]# vim /etc/samba/smb.conf
[root@localhost ~]# smbclient -L //172.25.254.111 -U student
Enter student's password:
Domain=[WESTOS] OS=[Windows 6.1] Server=[Samba 4.2.3]
Sharename Type Comment
--------- ---- -------
DATA Disk local directory /westos
IPC$ IPC IPC Service (Samba Server Version 4.2.3)
student Disk Home Directories
Domain=[WESTOS] OS=[Windows 6.1] Server=[Samba 4.2.3]
Server Comment
--------- -------
Workgroup Master
--------- -------
7:登陆自己建立的共享目录
[root@localhost ~]# mkdir /westos
[root@localhost ~]# touch /westos/westosfile{1..4}
[root@localhost ~]# ls -Zd /westos
drwxr-xr-x. root root unconfined_u:object_r:default_t:s0 /westos
[root@localhost ~]# semanage fcontext -a -t samba_share_t '/westos(/.*)?'
[root@localhost ~]# restorecon -RvvF /westos/
restorecon reset /westos context unconfined_u:object_r:default_t:s0->system_u:object_r:samba_share_t:s0
restorecon reset /westos/westosfile1 context unconfined_u:object_r:default_t:s0->system_u:object_r:samba_share_t:s0
restorecon reset /westos/westosfile2 context unconfined_u:object_r:default_t:s0->system_u:object_r:samba_share_t:s0
restorecon reset /westos/westosfile3 context unconfined_u:object_r:default_t:s0->system_u:object_r:samba_share_t:s0
restorecon reset /westos/westosfile4 context unconfined_u:object_r:default_t:s0->system_u:object_r:samba_share_t:s0
[root@localhost ~]# smbclient //172.25.254.111/DATA -U student
Enter student's password:
Domain=[WESTOS] OS=[Windows 6.1] Server=[Samba 4.2.3]
smb: \> ls
. D 0 Mon Aug 21 06:34:01 2017
.. D 0 Mon Aug 21 06:33:46 2017
westosfile1 N 0 Mon Aug 21 06:34:01 2017
westosfile2 N 0 Mon Aug 21 06:34:01 2017
westosfile3 N 0 Mon Aug 21 06:34:01 2017
westosfile4 N 0 Mon Aug 21 06:34:01 2017
10473900 blocks of size 1024. 7261064 blocks available
smb: \>
[root@localhost ~]# vim /etc/samba/smb.conf
[root@localhost ~]# ls -Zd /etc #配置文件不用改标签
drwxr-xr-x. root root system_u:object_r:etc_t:s0 /etc
[root@localhost ~]# smbclient //172.25.254.111/CONFIG -U student
Enter student's password:
Domain=[WESTOS] OS=[Windows 6.1] Server=[Samba 4.2.3]
smb: \> ls
. D 0 Mon Aug 21 05:56:58 2017
.. D 0 Mon Aug 21 06:33:46 2017
fstab N 313 Tue May 6 21:22:57 2014
crypttab N 0 Tue May 6 21:22:57 2014
mtab R 0 Mon Aug 21 06:45:40 2017
pki D 0 Tue May 6 21:27:13 2014
rpm D 0 Thu Jul 10 18:36:36 2014
yum D 0 Tue May 6 21:24:49 2014
issue N 23 Tue Apr 1 09:28:10 2014
binfmt.d D 0 Wed Apr 2 09:30:23 2014
issue.net N 22 Tue Apr 1 09:28:10 2014
modules-load.d D 0 Wed Apr 2 09:30:23 2014
os-release N 493 Tue Apr 1 09:28:10 2014
fonts D 0 Thu Jul 10 18:22:37
8:让异地电脑有上传文件权限
[root@localhost ~]# chmod 777 /westos
[root@localhost ~]# getsebool -a | grep samba
samba_create_home_dirs --> off
samba_domain_controller --> off
samba_enable_home_dirs --> on
samba_export_all_ro --> on
samba_export_all_rw --> off
samba_portmapper --> off
samba_run_unconfined --> off
samba_share_fusefs --> off
samba_share_nfs --> off
sanlock_use_samba --> off
use_samba_home_dirs --> off
virt_sandbox_use_samba --> off
virt_use_samba --> off
[root@localhost ~]# vim /etc/samba/smb.conf
[root@localhost ~]# mount -o username=student,password=student //172.25.254.111/DATA /mnt
[root@localhost ~]# cd /mnt
[root@localhost mnt]# ls
westosfile1 westosfile2 westosfile3 westosfile4
[root@localhost mnt]# touch file
[root@localhost mnt]# ls
file westosfile1 westosfile2 westosfile3 westosfile4
[root@localhost mnt]# rm -fr file
[root@localhost mnt]# ls
westosfile1 westosfile2 westosfile3 westosfile4
9:多用户共享目录
[root@localhost ~]# vim /etc/samba/smb.conf
[root@localhost ~]# systemctl restart smb.service
[root@localhost ~]# vim /root/smbpassword [root@localhost ~]# chmod 600 /root/smbpassword [root@localhost ~]# mount -o credentials=/root/smbpassword,multiuser,sec=ntlmssp //172.25.254.111/DATA /mnt
[root@localhost ~]# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/vda1 10473900 7620580 2853320 73% /
devtmpfs 927072 0 927072 0% /dev
tmpfs 942660 84 942576 1% /dev/shm
tmpfs 942660 17024 925636 2% /run
tmpfs 942660 0 942660 0% /sys/fs/cgroup
/dev/mapper/vg0-vo 483670 2399 451780 1% /home
/dev/loop0 3947824 3947824 0 100% /var/www/html/rhel7.2
//172.25.254.111/DATA 10473900 3205196 7268704 31% /mnt