4

I can only mount a remote cifs share as root even though I am using uid and gid with a valid user.

This did work for years, with fstab remaining unchanged. I have been patching (this is openSUSE Leap 15.3) so I'm wondering if something has been broken or deprecated. If there's no obvious answer, how best do I troubleshoot this?

# whoami
root

# uname -a
Linux my_user7 5.3.18-59.40-preempt #1 SMP PREEMPT Mon Jan 3 18:43:20 UTC 2022 (34edd9c) x86_64 x86_64 x86_64 GNU/Linux

# ls -lah /external/
total 0
drwxr-xr-x 1 root   root   76 Apr 13  2021 .
drwxr-xr-x 1 root   root  422 Sep  4 14:26 ..
drwxr-xr-x 1 my_user users   0 Jul 28  2018 Data1
drwxr-xr-x 1 my_user users   0 Nov 26  2019 Data2
drwxr-xr-x 1 my_user users   0 Jul 27  2018 Data3
drwxr-xr-x 1 my_user users   0 Jul 27  2018 Data4
drwxr-xr-x 1 my_user users   0 Jul 27  2018 Data5
drwxr-xr-x 1 my_user users   0 Apr 13  2021 Data6

# mount -v -t cifs -o username=my_user,password=my_pass,vers=1.0,uid=my_user,gid=users //192.168.1.1/Data5 /external/Data5
mount.cifs kernel mount options: ip=192.168.1.1,unc=\\192.168.1.1\Data5,vers=1.0,uid=1000,gid=100,user=my_user,pass=********

# ls -lah /external/
total 0
drwxr-xr-x 1 root   root   76 Apr 13  2021 .
drwxr-xr-x 1 root   root  422 Sep  4 14:26 ..
drwxr-xr-x 1 my_user users   0 Jul 28  2018 Data1
drwxr-xr-x 1 my_user users   0 Nov 26  2019 Data2
drwxr-xr-x 1 my_user users   0 Jul 27  2018 Data3
drwxr-xr-x 1 my_user users   0 Jul 27  2018 Data4
drwxrwxrwx 1 root   root     0 Jul 27 14:14 Data5
drwxr-xr-x 1 my_user users   0 Apr 13  2021 Data6

# id my_user
uid=1000(my_user) gid=100(users) groups=491(cdrom),463(vboxusers),100(users)

What am I missing?

Thanks in advance.

EDIT: Additional info...

mount cifs can only be run as root

# whoami
my_user

# mount -v -t cifs -o username=my_user,password=my_pass,vers=1.0,uid=my_user,gid=users //192.168.1.1/Data5 /external/Data5
This program is not installed setuid root -  "user" CIFS mounts not supported.

It will run OK if I sudo

# sudo mount -v -t cifs -o username=my_user,password=my_pass,vers=1.0,uid=my_user,gid=users //192.168.1.1/Data5 /external/Data5
mount.cifs kernel mount options: ip=192.168.1.1,unc=\\192.168.1.1\Data5,vers=1.0,uid=1000,gid=100,user=my_user,pass=********

But with the same end result, we're mounted as root

# ls -lah /external/
total 0
drwxr-xr-x 1 root   root   76 Apr 13  2021 .
drwxr-xr-x 1 root   root  422 Sep  4 14:26 ..
drwxr-xr-x 1 my_user users   0 Jul 28  2018 Data1
drwxr-xr-x 1 my_user users   0 Nov 26  2019 Data2
drwxr-xr-x 1 my_user users   0 Jul 27  2018 Data3
drwxr-xr-x 1 my_user users   0 Jul 27  2018 Data4
drwxrwxrwx 1 root   root     0 Jul 27 14:14 Data5
drwxr-xr-x 1 my_user users   0 Apr 13  2021 Data6

My fstab looks as follows

# cat /etc/fstab | grep Data5
//192.168.1.1/Data5                       /external/Data5            cifs   user,nofail,x-systemd.device-timeout=10,x-systemd.automount,x-systemd.idle-timeout=60,uid=my_user,gid=users,username=my_user,password=my_pass,vers=1.0 0  0

Which runs successfully

# sudo mount -a

But still mounts as root

# ls -lah /external/
total 16K
drwxr-xr-x 1 root   root    76 Apr 13  2021 .
drwxr-xr-x 1 root   root   422 Sep  4 14:26 ..
drwxr-xr-x 1 my_user users  12K Nov  4 14:14 Data1
drwxr-xr-x 8 my_user users  170 May  6  2021 Data2
drwxr-xr-x 2 my_user users 4.0K Oct  4 10:04 Data3
drwxr-xr-x 5 my_user users  110 Nov 19 12:02 Data4
drwxrwxrwx 1 root   root      0 Jul 27 14:14 Data5
drwxr-xr-x 1 my_user users    0 Apr 13  2021 Data6

Still baffled!

Edit II...

A partial solution.

Adding forceuid and forcegid fixes the ownership but I can't set the mode, even with file_mode and dir_mode:

# mount -v -t cifs -o username=my_user,password=my_pass,uid=my_user,gid=users,forceuid,forcegid,file_mode=0755,dir_mode=0755,vers=1.0 //192.168.1.1/Data5 /external/Data5
mount.cifs kernel mount options: ip=192.168.1.1,unc=\\192.168.1.1\Data5,forceuid,forcegid,file_mode=0755,dir_mode=0755,vers=1.0,uid=1000,gid=100,user=my_user,pass=********

# ls -lah /external/
total 0
drwxr-xr-x 1 root   root   76 Jan 25 14:20 .
drwxr-xr-x 1 root   root  422 Sep  4 14:26 ..
drwxr-xr-x 1 my_user users   0 Jul 28  2018 Data1
drwxr-xr-x 1 my_user users   0 Nov 26  2019 Data2
drwxr-xr-x 1 my_user users   0 Jul 27  2018 Data3
drwxr-xr-x 1 my_user users   0 Jul 27  2018 Data4
drwxrwxrwx 1 my_user users   0 Jul 27 14:14 Data5
drwxr-xr-x 1 my_user users   0 Apr 13  2021 Data6

Just need to figure out the mode, now...

3
  • What you are missing is the information returned when you try and do it as an ordinary user. We cannot help you without giving us some information as to what happens. Commented Jan 24, 2022 at 22:24
  • Thanks for the feedback but I can only mount as root: # whoami my_user # mount -v -t cifs -o username=my_user,password=my_pass,vers=1.0,uid=mgould,gid=users //192.168.1.1/Data5 /external/Data5 This program is not installed setuid root - "user" CIFS mounts not supported. It will run if I sudo # sudo mount -v -t cifs -o username=my_user,password=my_pass,vers=1.0,uid=my_user,gid=users //192.168.1.1/Data5 /external/Data5 mount.cifs kernel mount options: ip=192.168.1.1,unc=\\192.168.1.1\Data5,vers=1.0,uid=1000,gid=100,user=my_user,pass=******** But we're still mounted as root.
    – Marcus G
    Commented Jan 25, 2022 at 9:27
  • 1
    Please don’t use # as your shell prompt when you’re not root — at least not in examples — it’s  very  confusing. Commented Apr 13, 2022 at 18:48

3 Answers 3

1

It occurs to me that as (a) I'm the only one accessing this share and (b) mode changes are not written back to the CIFS filesystem anyway, it doesn't matter whether the mode is 777 or 755. Therefore, the following fixes the issue:

# mount -v -t cifs -o username=my_user,password=my_pass,uid=my_user,gid=users,forceuid,forcegid,vers=1.0 //192.168.1.1/Data5 /external/Data5
mount.cifs kernel mount options: ip=192.168.1.1,unc=\\192.168.1.1\Data5,forceuid,forcegid,file_mode=0755,dir_mode=0755,vers=1.0,uid=1000,gid=100,user=my_user,pass=********

# ls -lah /external/
total 0
drwxr-xr-x 1 root   root   76 Jan 25 14:20 .
drwxr-xr-x 1 root   root  422 Sep  4 14:26 ..
drwxr-xr-x 1 my_user users   0 Jul 28  2018 Data1
drwxr-xr-x 1 my_user users   0 Nov 26  2019 Data2
drwxr-xr-x 1 my_user users   0 Jul 27  2018 Data3
drwxr-xr-x 1 my_user users   0 Jul 27  2018 Data4
drwxrwxrwx 1 my_user users   0 Jul 27 14:14 Data5
drwxr-xr-x 1 my_user users   0 Apr 13  2021 Data6

And the fstab equivalent:

# cat /etc/fstab | grep Data5
//192.168.1.1/Data5 /external/Data5 cifs user,nofail,x-systemd.device-timeout=10,x-systemd.automount,x-systemd.idle-timeout=60,uid=my_user,gid=users,credentials=/root/.data5cred,vers=1.0,forceuid,forcegid 0  0

Hope this helps somebody.

Note 1: If anyone does know the solution to fixing rights I'm still interested from a learning perspective.

Note 2: If anyone knows why I suddenly needed to specify forceuid and forcegid I'd be very interested to hear!

Cheers, all!

0

As your comment has stated, mount.cifs is not SUID and is therefore unable to perform mount as non-root. /bin/mount however is but can only be used for paths listed in /etc/fstab.

If this worked before, then it is likely somene has set the SUID bit on /sbin/mount.cifs which would be frowned upon.

You are best to put the details into /etc/fstab with the login details contained in a restricted file. Details are in man mount.cifs, but would be something like:

//192.168.1.1/Data5 /external/Data5 cifs username=my_user,credentials=<some file>,user 0 0

That some file should contain username, password and domain, details in the man page.

4
  • Thanks but changing fstab does not work, either. For the avoidance of doubt, mount.cifs works fine but the uid= and gid= settings are ignored and the share is mounted root:root instead of my_user:users. This failing share is on an old NAS thing that hasn't had a software or firmware upgrade for two years. I have another working cifs share (a real Windows 10 PC) which is what makes this utterly bizarre. So... One works, one fails. Both the same syntax.
    – Marcus G
    Commented Jan 25, 2022 at 11:24
  • And what are the ownership of files within ` /external/Data5`? Commented Jan 25, 2022 at 12:12
  • It's root:root all the way down.
    – Marcus G
    Commented Jan 25, 2022 at 14:19
  • See Edit II in original post re forceuid and forcegid...
    – Marcus G
    Commented Jan 25, 2022 at 17:16
0

I have had to Exchange my personal details on the a public server for all to see before I could use the personal details to connect

sudo touch cred.txt
echo "USER hangbroktim PASS CreepyPoniesInTheNight34767248932654678497632785468932458769823584" >> cred.txt
mount -v -t cifs -o passloader cred.txt

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .