ユーザ名をマッピングする必要がある。
もしマッピングしてないと、root権限としてマウントされてしまう
mount -t cifs -o uid=takuya,gid=www-data,username=SMBUSER,password=SMBPASS //IPADDR/PATH TARGET
username でログインし、マウントして uid にマッピングする。uid と書いているが、ローカルユーザの名前で行ける。
uid,gid を設定してマウントしたとき
ユーザ名が、指定した名前でマウントされる。
takuya@:~$ sudo mount -t cifs -o uid=takuya,gid=takuya,username=takuya,password=XXXX //192.168.1.222/takuya test takuya@:~$ ls -alt test 合計 60 drwxrwxr-x 42 takuya takuya 8192 2月 21 17:53 .. drwxr-xr-x 2 takuya takuya 0 2月 21 17:27 . drwxr-xr-x 2 takuya takuya 0 2月 18 14:15 .ssh -rwxr-xr-x 1 takuya takuya 119 2月 18 01:43 .vimrc -rwxr-xr-x 1 takuya takuya 302 2月 18 01:33 .bash_logout takuya@:~$ sudo umount test
uid, gid を省略したとき
root でマウントされる。このあたりは、ちゃんと知ってないとパニックになります。
takuya@:~$ sudo mount -t cifs -o username=takuya,password=XXXX //192.168.1.2222/takuya test takuya@:~$ ls -alt test 合計 60 drwxrwxr-x 42 takuya takuya 8192 2月 21 17:53 .. drwxr-xr-x 2 root root 0 2月 21 17:27 . drwxr-xr-x 2 root root 0 2月 18 14:15 .ssh -rwxr-xr-x 1 root root 119 2月 18 01:43 .vimrc -rwxr-xr-x 1 root root 302 2月 18 01:33 .bash_logout takuya@:~$ sudo umount test
パスワードファイルを使う。
また、パスワードは、直接記載せずに、ファイルに書くことができる
ただし、cifs-utils のインストールが必要
sudo apt install cifs-utils
ファイルを作る。
cat smb_credetials.192.168.1.222 ### smb 接続先の設定 username=takuya password=XXXXXX
SAMBA側の設定
上記が動いているときの、Sambaのconfは次の通り。
ほとんど初期設定。home追加したくらい。
testparm -s /etc/samba/smb.conf Load smb config files from /etc/samba/smb.conf Loaded services file OK. Weak crypto is allowed Server role: ROLE_STANDALONE # Global parameters [global] log file = /var/log/samba/log.%m logging = file map to guest = Bad User max log size = 1000 obey pam restrictions = Yes pam password change = Yes panic action = /usr/share/samba/panic-action %d passwd chat = *Enter\snew\s*\spassword:* %n\n *Retype\snew\s*\spassword:* %n\n *password\supdated\ssuccessfully* . passwd program = /usr/bin/passwd %u server role = standalone server server string = %h server (Samba, Ubuntu) unix password sync = Yes idmap config * : backend = tdb [homes] browseable = No comment = Home Directories create mask = 0740 directory mask = 0740 read only = No valid users = %S