0

I have an external USB SSD with a single partition formatted with ext4. The PC is running Ubuntu 20.04. When I plug it and click on the button to mount it, it just gets mounted without asking any password and I can copy files into it. Then I ummount it by pressing the button and that's it.

I want to achieve the same but from command line. Been looking at some answers here but cannot get it to work. For example this one still requests me the password.

How can I do this?

1 Answers1

2

The mounting from your desktop is done using UDisks a system daemon that allows (some) unprivileged mounts via polkit. UDisks has a command line tool you can use called udisksctl:

udisksctl mount -b /dev/sdxY

and

udisksctl unmount -b /dev/sdxY

If udisksctl asks you for password, that means that some requirements needed for the unprivileged mount are not met. For example you are trying to mount a system disk (not a removable one) or you are not logged in an active session etc. If this is the case, UDisks won't help you and you need to add your device to fstab with the user or users option which allows unprivileged mounts (even just with the simple mount command). For an external drive that is not available all the time add the noauto option so the system doesn't try to mount it during boot. So add a line similar to this to your fstab

UUID=<uuid of your drive> /media/mySSD   ext4  defaults,noauto,users  0 0

(you can get the UUID from lsblk -f)

and then just mount it with mount /media/mySSD.

  • I added the line to /etc/fstab as you said (replaced the UUID and path for /media/mySSD only). Now when I run mount /dev/sdb1 /media/230302_red I still get the answer mount: only root can do that. Do I have to restart something before it works? – user171780 Mar 03 '23 at 09:05
  • 1
    With this you need to run either mount /dev/sdb1 or mount /media/230302_red. If you specify both the device and mountpoint, mount will ignore fstab. – Vojtech Trefny Mar 03 '23 at 09:32
  • Thanks, with mount /dev/sdb1 now it is mounted without need for sudo. However, I don't have permission to read or write there. A chmod 777 /media/230302_red seems to have solved the problem. Not sure if it is the correct way, but it worked. – user171780 Mar 03 '23 at 10:47
  • Note that mount /media/230302_red does not work (asks for sudo). Maybe it is better if you change it in your answer in case someone else ends up here. – user171780 Mar 03 '23 at 10:48