Linux上mount 掛載windows共用檔案許可權問題

來源:互聯網
上載者:User

標籤:mount   for   共用檔案   www   寫入   tps   auto   span   ack   

在伺服器部署的時候需要把檔案夾設定在windows的共用檔案上。在使用mount命令掛載到linux上後。檔案路徑和檔案都是可以訪問,但是不能寫入,導致系統在上傳檔案的時候提示“許可權不夠,沒有寫入權限”。用"ls-l"查看掛載檔案的使用權限設定是drwxr-xr-x,很明顯沒有寫入權限。想當然使用chmod來變更檔夾許可權,結果提示許可權不夠。root和目前使用者都不能正常修改許可權。於是無語,不知如何進行了。
(windows許可權記得在進階共用設定->公用->是否開啟密碼驗證)
使用下面命令Linux上掛載windows上共用資料夾時,成功之後在Linux中發現可以訪問,但不能修改。

[plain] view plain copy  
  1. mount -t cifs -o username="***",password="***"  //WindowsHost/sharefolder  /home/xxx/shared  

 

同時使用ls -l shared會發現shared目錄所有者和使用者組均是root,即使使用sudo chmod和sudo chown修改許可權也提示許可權不夠。不過可以添加兩個參數即可達到我們所要的效果:

[plain] view plain copy  
  1. mount -t smbfs -o username="***",password="***",gid="***",uid="****" //WindowsHost/sharefolder  /home/xxx/shared  



屬性中的gid、uid,是你想要讓掛載屬於哪個使用者的gid和uid。至於這個gid和uid,你可以使用id username來獲得,比如說我的xxx,使用者獲得的gid和uid就是1000。
同時上述命令中的username和password是訪問用來WindowsHost的。


例:我是用lnmp一鍵安裝包的,運行nginx的使用者的www,我就用id www查詢他的gid uid 然後在進行掛載就不會出現許可權的問題了!

卸載掛載目錄:sudo umount shared

 

機器重啟自動掛載,vi /etc/fstab最後加入: 

[plain] view plain copy  
  1. //WindowsHost/sharefolder /home/xxx/shared cifs defaults,auto,username="xxxx",password="***",gid="1000",uid="1000" 0 0   

Linux上mount 掛載windows共用檔案許可權問題

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.