samba安裝
-
root用戶下直接使用以下命令
apt-get install samba
-
若是普通用戶下使用以下命令
sudo apt-get install smaba
samba配置
samba的配置文件在/etc/samba/路徑下,文件名爲smb.conf,注意需要root用戶權限才能編輯該文件,我是用root用戶下使用vim進行編輯修改的。
在文件末尾添加以下內容
[test]
comment = samba test
path = /home/d/share //共享文件路徑
browseable = yes
read only = no
guest ok = yes
writable = yes
添加samba用戶
smbpasswd -a 用戶名
接着需要兩次輸入密碼
此處設置的用戶和密碼,是用來登錄用的
可能出現的錯誤
-
執行smbpasswd有可能會出現以下錯誤:
bash: smbpasswd: command not found
解決辦法:出現該錯誤表示samba-client沒有安裝
執行命令apt-get install samba-client
-
執行samba-client命令可能會出現以下錯誤:
smbclient: Depends: libwbclient0 (= 2:4.5.16+dfsg-1+deb9u1) but 2:4.5.16+dfsg-1+deb9u2 is to be installed
解決辦法:
執行命令 apt-get autoremove libwbclient0 //卸載之前安裝的版本 執行命令 apt-get install libwbclient0=2:4.5.16+dfsg-1+deb9u1 //安裝所需要的版本
通過以上命令即可解決問題,此時可以執行apt-get install samba-client,將成功安裝samba-client
起動samba服務
使用命令 systemctl start smb
執行以上命令會報錯:Failed to start smb.service: Unit smb.service not found
到目錄/etc/init.d目錄下可以發現沒有smb文件,但可以發現smnd和nmbd文件,使用這兩個執行文件來起動samba服務,執行以下命令:
systemctl restart smbd.service nmbd.service
若執行上述命令時,出現以下錯誤:
Failed to restart smbd.service: Unit smbd.sercvice not found
Failed to restart nmbd.service: Unit nmbd.service not found
出現上述錯誤的原因是因爲samba沒有安裝成功,因此需要執行apt-get install samba,重新安裝samba,安裝完成以後,再執行以上命令,即可成功起動samba服務
若要查看samba服務是否起動成功,只需要執行命令systemctl status smbd.service,執行該命令後,可以在終端上看到active(running),表明samba服務已經起動成功。