第一步:安裝samba服務
》yum install samba
第二步:啓動samba服務
》systemctl start smb
查看samba的狀態
》systemctl status smb
看到Active就說明在運行中了
第三步:關閉防火牆
》systemctl stop firewalld.service //停止服務
》systemctl disable firewalld.service //關閉開機啓動
同時還有這一步
設置SELINUX=disabled(需要重啓電腦)
vi /etc/selinux/config文件中設置SELINUX=disabled ,然後重啓服務器。
第四步:需要添加一個用戶來訪問文件
》useradd lcd //添加用戶
》passwd lcd //修改密碼
創建samba用戶
》smbpasswd -a lcd
第五步:修改samba的配置文件
》vi /etc/samba/smb.conf //進入配置文件
5.1將global中進行一下全局配置更改:
workgroup = WORKGROUP//定義工作組,也就是windows中的工作組概念
security = user //安全認證方式採用user方式
ntlm auth = yes //否則windows7訪問用戶會認證失敗
5.2在conf中添加新的用戶配置(讓4的配置生效)
[lcd]
path = /cloud/lcd //共享目錄
browsable =yes
writable = yes //目錄可讀可寫
read only = no
修改後的smb.conf如下:
[global]
workgroup = WORKGROUP
security = user
passdb backend = tdbsam
printing = cups
printcap name = cups
load printers = yes
cups options = raw
ntlm auth = yes
[homes]
comment = Home Directories
valid users = %S, %D%w%S
browseable = No
read only = No
inherit acls = Yes
[printers]
comment = All Printers
path = /var/tmp
printable = Yes
create mask = 0600
browseable = No
[print$]
comment = Printer Drivers
path = /var/lib/samba/drivers
write list = @printadmin root
force group = @printadmin
create mask = 0664
directory mask = 0775
[lcd]
path = /cloud/lcd
browsable =yes
writable = yes
read only = no
第六步:設置想要共享目錄的文件權限
給共享目錄添加寫權限,這樣可以從windows向linux中寫入文件。比如我這裏設置\home爲共享目錄,那在終端輸入以下命令即可
chmod -R 777 /cloud/lcd (可寫 w=4 可讀 r=2 可執行 x=1 )
第七步:重啓samba服務
》systemctl restart smb
測試及使用:
win7:\10.xx.xx.xx\lcd 提示輸入賬號密碼。
————————————————
版權聲明:本文爲CSDN博主「sparrowwf」的原創文章,遵循 CC 4.0 BY-SA 版權協議,轉載請附上原文出處鏈接及本聲明。
原文鏈接:https://blog.csdn.net/sparrowwf/article/details/81064318
先掛載好CentOS光盤文件
[root@localhost /]# yum install samba
[root@localhost /]useradd -s /sbin/nologin jitai1
[root@localhost /]smbpasswd -a jitai1
[root@localhost /]# vi /etc/samba/smb.conf
[root@localhost /]# cat /etc/samba/smb.conf
[global]
workgroup = SAMBA
workgroup = WORKGROUP
security = user
ntlm auth = yes
passdb backend = tdbsam
printing = cups
printcap name = cups
load printers = yes
cups options = raw
[homes]
comment = Home Directories
valid users = %S, %D%w%S
browseable = No
read only = No
inherit acls = Yes
[printers]
comment = All Printers
path = /var/tmp
printable = Yes
create mask = 0600
browseable = No
[print$]
comment = Printer Drivers
path = /var/lib/samba/drivers
write list = @printadmin root
force group = @printadmin
create mask = 0664
directory mask = 0775
[jitai1]
comment = jitai1
path = /tmp/jitai1
browsable = yes
writable = yes
read only = no
win 10 即可網絡驅動器映射jitai1目錄。
win10的記事本,輸入如下,保存爲startupZ.bat文件
net use Z: \10.24.11.93\jitai1 jitai1 /user:jitai1 /persistent:yes
1.首先在電腦的左下角,點擊開始菜單,在菜單中選擇“運行”選項。
2.然後在運行窗口中輸入“shell:startup”,點擊確定。
3.此時打開的文件夾窗口就是“windows10啓動”界面。
4.將startupZ.bat 放入該目錄,開機自動映射網絡驅動器。
A服務器10.24.11.93:
[root@cent7x64 ~]# ssh-keygen -t rsa
[root@cent7x64 ~]# cat ~/.ssh/id_rsa.pub
[root@cent7x64 ~]# scp id_rsa.pub [email protected]:/root/.ssh/authorized_keys
B服務器10.24.11.91:
[root@cent7x64 ~]# ssh-keygen -t rsa
[root@cent7x64 ~]# cat ~/.ssh/id_rsa.pub
[root@cent7x64 ~]# scp id_rsa.pub [email protected]:/root/.ssh/authorized_keys
從10.24.11.93拷貝文件到10.24.11.91:
[root@cent7x64 ~]cat bakjitai1.sh
#!/bin/bash
scp -r /tmp/jitai1/ [email protected]:/tmp/jitai1date +%Y%m%d
date +%H:%M:%S
[root@localhost tmp]# cat rmrfjitai1.sh
!#/bin/bash
rm -rf /tmp/jitai1/.
[root@localhost tmp]# cat /etc/crontab
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
For details see man 4 crontabs
Example of job definition:
.---------------- minute (0 - 59)
| .------------- hour (0 - 23)
| | .---------- day of month (1 - 31)
| | | .------- month (1 - 12) OR jan,feb,mar,apr ...
| | | | .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
| | | | |
* user-name command to be executed
/2 * root /tmp/bakjitai1.sh
/3 * root /tmp/rmrfjitai1.sh
定時拷貝就不用密碼驗證了。