1. 程式人生 > >Linux上mount 掛載windows共享檔案許可權問題

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

在伺服器部署的時候需要把資料夾設定在windows的共享檔案上。在使用mount命令掛載到linux上後。檔案路徑和檔案都是可以訪問,但是不能寫入,導致系統在上傳檔案的時候提示“許可權不夠,沒有寫許可權”。用"ls-l"檢視掛載檔案的許可權設定是drwxr-xr-x,很明顯沒有寫許可權。想當然使用chmod來更改資料夾許可權,結果提示許可權不夠。root和當前使用者都不能正常修改許可權。於是無語,不知如何進行了。

使用下面命令Linux上掛載windows上共享資料夾時,成功之後在Linux中發現可以訪問,但不能修改。
mount -t cifs -o username="***",password="***"  //WindowsHost/sharefolder  /home/xxx/shared

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

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的。


解除安裝掛載目錄:sudo umount shared

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

//WindowsHost/sharefolder /home/xxx/shared cifs defaults,auto,username="xxxx",password="***",gid="1000",uid="1000" 0 0