1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

NASをUbuntuの起動時に自動マウントでディレクトリへの権限設定方法

Posted at

結論

/etc/fstabに以下を記述

//NAS_IP/共有ディレクトリ /mnt/マウント先 cifs credentials=/etc/cifs-utils/smbcredentials,file_mode=0777,dir_mode=0777,uid=1000,gid=1000 0 0

/etc/cifs-utils/smbcredentialsに以下を記述し、

username=
password=

以下のコマンドを実行

sudo chmod 500 /etc/cifs-utils/smbcredentials

説明

前提として、Ubuntuの環境とNASがちゃんと利用できるように構築されているとします。

まず、cifsが入ってなければインストールしましょう。

sudo apt install cifs

そしたら、vimなどで/etc/fstabを開き、以下の内容を記述します。

//NAS_IP/共有ディレクトリ /mnt/マウント先 cifs credentials=/etc/cifs-utils/smbcredentials,file_mode=0777,dir_mode=0777,uid=1000,gid=1000 0 0

IPアドレスやパスは適宜読み替えて使ってください。
今回はcredentialsを使い、そこにユーザ名とパスワードを書くことで漏洩リスクを"多少"減らしています。
file_modedir_modeは通常の権限を設定するときと同様の使い方をします。これで共有ディレクトリに対して管理者権限を持っていないユーザでも書き読みできます(もちろん他の権限の設定も可能です)。

次にcredentialsの設定に移ります。/etc/cifs-utils/smbcredentialsに以下を記述します。

username=
password=

例えばユーザ名がTakashiなら、username=Takashi、パスワードがHogeなら、password=hogeとしてください。

最後に、credentialsの権限を制限して終了します。

sudo chmod 500 /etc/cifs-utils/smbcredentials

以上です。

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?