5、Samba实践二
共享一个目录,使用用户名和密码登录后才可以访问,要求可以读写;
[global] 部分内容如下:
[global]
workgroup = WORKGROUP
server string = Samba Server Version %v
security = user
passdb backend = tdbsam
load printers = yes
cups options = raw
还需加入:
[myshare]
comment = share for users
path = /samba
browseable = yes
writable = yes
public = no
创建目录:mkdir /samba
修改权限:chmod 777 /samba
创建系统账号:
useradd user1
useradd user2
添加user1/user2为samba账户:
pdbedit -a user1 #需要输入用户密码2次
pdbedit -a user2
列出samba所有账号: pdbedit –L
重启服务 service smb restart
测试:浏览器输入file://192.168.22.30/myshare
运行输入:\\192.168.22.30 或 \\192.168.22.30\myshare
进入\\192.168.22.30 弹出对话框,需要输入user1 用户名和密码,登录后,除了myshare共享文件夹,还有user1的用户家目录;user1拥有对目录的读写权限;
[root@linuxidc 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: \\linuxidc\user1
HomeDir Drive:
Logon Script:
Profile Path: \\linuxidc\user1\profile
Domain: linuxidc
Account desc:
Workstations:
Munged dial:
Logon time: 0
Logoff time: never
Kickoff time: never
Password last set: 一, 25 5月 2015 01:39:08 CST
Password can change: 一, 25 5月 2015 01:39:08 CST
Password must change: never
Last bad password : 0
Bad password count : 0
Logon hours : FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
12 [root@linuxidc samba]# pdbedit -L
user1:502:
实验测试,暂停用户,恢复用户,删除用户;
samba服务端,先暂停用户,账号标记为[DU],正常状态为[U];客户端访问,提示账号不可用;
[root@linuxidc 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服务端恢复用户,账号标记为[U];客户端访问,恢复正常;
[root@linuxidc 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服务端删除用户,客户端访问,会报错账号不可用;
[root@linuxidc 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访问samba共享文件
安装客户端软件 yum install -y samba-client
命令格式:smbclient //IP/共享名 -U 用户名
如:smbclient //127.0.0.1/share 如果是匿名访问可以省略掉-U
mount挂载samba目录:mount -t cifs //192.168.0.22/myshare /mnt -o username=user1,password=123456 使用用户密码登陆的;
mount -t cifs //192.168.0.22/myshare /mnt 匿名访问不需要-o参数;
如执行命令提示参数有错,还需要安装cifs-utils包;
Linux客户端测试samba共享:
故意输入错误密码,会报错登录失败LOGON_FAILURE;输入正确密码后进入,put上传文件,get下载文件;上传的文件smb服务器中查看所属主、组为user1;user1在共享文件夹可以新建目录,删除文件;help可以列出当前命令行可以执行的命令;
[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@linuxidc samba]# ls -l
-rwxr--r-- 1 user1 user1 1851 5月 25 02:02 1.sql
客户端mount挂载samba共享文件夹到本地:
[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)
Samba 的详细介绍:
Samba 的下载地址:
本文永久更新链接地址: