Linux mount write access

Mount cifs Network Drive: write permissions and chown

I have access to a cifs network drive. When I mount it under my OSX machine, I can read and write from and to it. When I mount the drive in ubuntu, using:

sudo mount -t cifs -o username=$,password=$ //server-address/folder /mount/path/on/ubuntu 

I am not able to write to the network drive, but I can read from it. I have checked the permissions and owner of the mount folder, they look like:

4.0K drwxr-xr-x 4 root root 0 Nov 12 2010 Mounted_folder 
chown: changing ownership of `/Volumes/Mounted_folder': Not a directory 

When I descend deeper into the network drive, and change the ownership there, I get the error that I have no permission to change the folder´s owner. What should I do to activate my write permission?

You can also use the noperm mount option similarly stated in my answer to this question: unix.stackexchange.com/a/375523/16287. This will give all users read and write access to the CIFS mount.

3 Answers 3

You are mounting the CIFS share as root (because you used sudo ), so you cannot write as normal user. If your Linux Distribution and its kernel are recent enough that you could mount the network share as a normal user (but under a folder that the user own), you will have the proper credentials to write file (e.g. mount the shared folder somewhere under your home directory, like for instance $HOME/netshare/ . Obviously, you would need to create the folder before mounting it).

An alternative is to specify the user and group ID that the mounted network share should used, this would allow that particular user and potentially group to write to the share. Add the following options to your mount: uid=,gid= and replace and respectively by your own user and default group, which you can find automatically with the id command.

sudo mount -t cifs -o username=$,password=$,uid=$(id -u),gid=$(id -g) //server-address/folder /mount/path/on/ubuntu 

If the server is sending ownership information, you may need to add the forceuid and forcegid options.

sudo mount -t cifs -o username=$,password=$,uid=$(id -u),gid=$(id -g),forceuid,forcegid, //server-address/folder /mount/path/on/ubuntu 

Источник

How To Set Write Permission On ext4 Partition In Ubuntu Linux

ext4 permission Ubuntu

When I last installed Ubuntu, I made an ext4 partition of around 80 Gb in notebook’s HDD.

The problem arouse when I tried to copy something on this partition. I was simply not able to copy anything in it or create a new file.

Apparently, I did not have ‘write permission’ on the said partition.

In this tutorial I’ll show you how to set write permission on ext4 partition in Ubuntu, in the correct way. Let’ssee how to do it.

Читайте также:  Linux where program installed

How to set write permission on ext4 partition in Ubuntu:

The tutorial is performed in Ubuntu and uses extensively command line. A little knowledge about file ownership in Linux system would be a plus. Even if you do not know, no worries. You can still follow the tutorial with ease. Just follow the steps below:

Step 1:

First this, you need to know the UUID of the ext4 partition. But before that it will be better to know the name of partition.

The name, in Ubuntu, would be like sdaX or something. To find that, use the following command in terminal (Ctrl+Alt+T):

Output of the command will look like this:

Check the disk partition in Ubuntu

You can find the name of the partition from its size, given under the Blocks field (in bytes). So in the picture above 78123008 roughly amounts to 78 Gb and thus it tells me that the partition name is sda7.

Now when you have the name, you can find the UUID by using the following command:

Output of the command looks like this:

Check the disk partition in Ubuntu

As you can see, with the partition name, you can easily identify the UUID.

Step 2:

Once you have the UUID, the next step is to find out where is the partition mounted.

Usually the location of the ext4 mount is /media/ . Where user_name is your own username.

You can also use $USER variable. It automatically takes your username.

You can display the mounted partitions in the following manner:

The output of the command for me was this:

Check the mounted drive

Now you see why I took the trouble of finding the UUID. If you have several partition mounted, you need to distinguish between them.

You can also see that only root has write on the mounted ext4 partition. You need to change the write permission for this partition here.

Step 3:

Now the easiest option is to give the write access to everyone using the infamous chmod 777.

But again, you won’t want to do that as it will give write access to anyone. Avoid using chmod 777 as far as it is possible.

Now, if not chmod 777, then what else? The file has root as owner and root as the group. Even ‘admin’ comes under ‘other’ group here.

What you can do do here is to change the group ownership of the mounted drive to admin. The admin group is generally named adm. You can use the following command to change the group owner:

sudo chgrp adm /media/itsfoss/56d0c0ab-60a0-48bf-955d-bc2f283009b6

Once you have changed the group, change the write permission for the group in the following manner:

sudo chmod g+w /media/itsfoss/56d0c0ab-60a0-48bf-955d-bc2f283009b6

Voila! Now you can copy-paste and create new files in the ext4 partition without any hindrance. And with added security, non-admin users will not be able to do so.

Читайте также:  Linux шрифты где находятся

This tutorial is similar to what you need to do in order to auto mount Windows partition in Ubuntu. Any questions or suggestions are always welcomed. 🙂

Источник

Mount USB drive with write permissions for everyone or specific user

Ultimately I need a perma-mount /dev/sdb2 to /home/storage with access right (rw) for the user media .

Using manual mount from command line.

server# sudo mount /dev/sdb2 /home/storage 

It mounts but the /home/storage receives root as owner and group and doesn’t allow media user to write there.

If I use mount command without sudo as the user media — i’m not allowed. Says only root can use mount.

If I use mount with options: server# sudo mount /dev/sdb2 /home/storage -o umask=000 I get what I need. A bit overdone of course, since the storage folder becomes writable for everyone. BUT — that is manually mounted — now i need it to remount on every reboot.

Remounting on reboot — using fstab **

So I thought I’ll be fine if I use fstab to mount this partition ( /dev/sdb2 ) every time i reboot. The fstab line I added:

UUID=8C52-C1CD /home/storage auto user,umask=000,utf8,noauto 0 0 

Got uuid with blkid . The fs type auto I changed a few times. I tried vfat too, but always on the reboot Ubuntu stops when processing fstab (I think) with the message (took from the log):

fsck from util-linux 2.20.1 /dev/sda5: clean, 120559/10969088 files, 19960144/43861504 blocks mount: unknown filesystem type 'static' mountall: mount /etc/fstab: [772] terminated with status 32 mountall: Filesystem could not be mounted: /etc/fstab: Skipping /etc/fstab: at user request 

And also — sudo mount -a never really does anything.

What am I doing wrong? I do suspect I messed up something:)

It seems fstab should hold only mounts for static drives, not any sort of usb stuff. I’m puzzled how then this works with all the people posting on the net their success stories.

However. if this is not possible — I would like to know how to remount my USB after every reboot. if not with fstab — then how? 🙂

Источник

How can I automatically set write permissions on mounting a usb drive in linux?

When I mount an external usb drive on linux (CentOs4), the permissions are by default set to read-only. Since there are multiple users on the computer who need to use the external drive, I want everybody to have rw permission for the entire drive. I also want them to be able to mount the drive if the computer has accidentially been shut down. They can use sudo mount to mount the drive, but this will only give them read permission, and I obviously don’t want to allow sudo chmod . Is there a default setting that I can change so that every new external usb disk automatically gets rw permissions?

3 Answers 3

To enable everyone rw access, the key is umask=0 option to mount command.

sudo mount -o umask=0,uid=nobody,gid=nobody /dev/something /mnt/somewhere 

umask=0 is enough, uid and gid just for sake of clarity, so you don’t see more ‘root’ owners than necessarily.

Читайте также:  Linux git clone https

@Tom’s answer (writing /etc/fstab entry) will allow you to skip sudo and if you write umask=0 as additional option there, you’ll get best of both worlds:

/dev/something /mnt/somewhere auto users,noatime,umask=0 0 0 

and everyone has access to all files.

Here’s technical note, if you wish to know details:

As man mount says, ‘umask=0’ will ensure that no additional rules apply to files access mode. For FAT filesystems (which are most widely used on USB disks), there’s no access mode stored. But your current process has some umask value set, you can see it if you run just umask in terminal. mount uses that as default and removes access mode of your umask value from all files on mounted disk. Most widely used umask values are (octal) 022 — no group and other write, and 027 — no group write, no any other access.

I get an error with ‘bad option’ if I add umask=0 0 0 as an entry in fstab. Does the umask -entry need to be the last entry? What does the managed=0 0 0 entry do that is currently last?

FWIW, the umask option is a VFAT-only option, i.e. the solution helps as long as the USB memory is uses the VFAT filesystem (which did not happen to be my case).

Thank you. But I had to alter it in order to make it work: sudo mount -o umask=0,uid=nobody /dev/something /mnt/somewhere It only works without setting the gid-parameter.

Add an entry to /etc/fstab. Here is an entry that I added just a few hours ago for my Seagate USB drive:

UUID=4ACC734ECC733375 /media/Linux ext3 errors=remount-ro,defaults,users,noatime,nodiratime 0 0

The key here is the «users» entry that allows users to mount and unmount the drive.

Edit: this works for specific drives — I don’t know if it can be enabled for all drives with one entry.

Type mount . This will give the current place it is at. Here is my output.

rick@rick-Main ~ $ mount /dev/sda4 on / type ext4 (rw,errors=remount-ro) proc on /proc type proc (rw,noexec,nosuid,nodev) sysfs on /sys type sysfs (rw,noexec,nosuid,nodev) none on /sys/fs/cgroup type tmpfs (rw) none on /sys/fs/fuse/connections type fusectl (rw) none on /sys/kernel/debug type debugfs (rw) none on /sys/kernel/security type securityfs (rw) udev on /dev type devtmpfs (rw,mode=0755) devpts on /dev/pts type devpts (rw,noexec,nosuid,gid=5,mode=0620) tmpfs on /run type tmpfs (rw,noexec,nosuid,size=10%,mode=0755) none on /run/lock type tmpfs (rw,noexec,nosuid,nodev,size=5242880) none on /run/shm type tmpfs (rw,nosuid,nodev) none on /run/user type tmpfs (rw,noexec,nosuid,nodev,size=104857600,mode=0755) none on /sys/fs/pstore type pstore (rw) /dev/sda6 on /media/DATA1 type vfat (rw,uid=1000,utf8,umask=077) binfmt_misc on /proc/sys/fs/binfmt_misc type binfmt_misc (rw,noexec,nosuid,nodev) systemd on /sys/fs/cgroup/systemd type cgroup (rw,noexec,nosuid,nodev,none,name=systemd) gvfsd-fuse on /run/user/1000/gvfs type fuse.gvfsd-fuse (rw,nosuid,nodev,user=rick) /dev/sdf1 on /media/usb0 type vfat (rw,noexec,nodev,sync,noatime,nodiratime) 

The last is my usb drive automouunted by Linux Mint.

sudo mount -t vfat /dev/sdf1 /media/usb0 -o rw,users,umask=0 

Источник

Оцените статью
Adblock
detector