動機&対処前の状況 #
外付けSSDを購入して容量増設した際、chown& chmodで適切に所有権と権限を設定(ls -lでrxが付いているのを確認)したがbash script等を実行しようとすると’Permission Denied’となってしまっていた。
原因 #
あくまで今回のケースの場合です。 まず
ls -lで適切な権限が付いていることを確認してください。
fstab(sudo mountとかを実行した際に読まれる設定ファイル)内で権限エラーがでるssdの設定を見ると
cat /etc/fstab
/dev/nvme1n1p1 /media/ssd2 ext4 user,auto,rw 0 2
となっていた。
これの何がまずいかと言うと、userを指定するとユーザーが自由にマウントできるようになるがnoexecが自動的にセットされてしまうのでexecを明示的に与える必要があった。
以下、情報ソース。
man fstab | grep user
user
allow a user to mount
man mount | grep user
user
Allow an ordinary user to mount the filesystem. The name of the mounting user is written to the mtab file (or to the private
libmount file in /run/mount on systems without a regular mtab) so that this same user can unmount the filesystem again. This option
implies the options noexec, nosuid, and nodev (unless overridden by subsequent options, as in the option line user,exec,dev,suid).
対処法 #
sudo blkidで該当のUUIDかマウントポイント(/dev/xxx)をコピーしてsudo umount の後に貼り付けて実行してアンマウントする。
target is busyと出たらどこかでファイル等を開いていたりするので閉じて再実行。
umountからでなくても環境によってはファイラ、ディスクツール等からアンマウントできたりする。
アンマウントできたら/etc/fstab を編集する。
自分の場合は
/dev/nvme1n1p1 /media/ssd2 ext4 user,exec,auto,rw 0 2
とexecを明示的につけてuserで非明示的にセットされたnoexecを上書きしておいた。
編集内容をcat /etc/fstabで確認したら再度マウント(sudo mount or 環境のGUIから)して無事に問題解決した。
以上。