DEAR PEOPLE FROM THE FUTURE: Here's what we've figured out so far...

Welcome! This is a Q&A website for computer programmers and users alike, focused on helping fellow programmers and users. Read more

What are you stuck on? Ask a question and hopefully somebody will be able to help you out!
+3 votes

I can only mount my USB stick with sudo mount /dev/sdb <path>. But my file manager can mount it without sudo because when I insert it into the USB port it's immediately available.
How do I mount a device from command line without sudo?

by

2 Answers

+2 votes
 
Best answer

The mount command requires superuser privileges, but you could mimic the effect of running a command without sudo by allowing user to run the command without a password, then adding an alias that invokes the sudo for you. For example:

Add this in visudo, replacing $user with the username (you might want the umount command as well):

$user ALL = NOPASSWD: /usr/bin/mount, /usr/bin/umount

Add this to your shell rc, e.g. ~/.bashrc:

alias mount="sudo mount" alias umount="sudo umount"

Apply to the current shell session: . ~/bashrc

Edit: the shell aliases should be one per line (as it did appear in preview), not sure why they got strung together after posting.


Another option is to use some utility like udisksctl which is already running as root to mount, e.g. udisksctl mount -b /dev/sdbN (mounting to /media/$user/*).

by
selected by
0

Turns out udisksctl is exactly what I needed. Looks like it's the same tool used by other desktops and file managers for auto mounting.

+1 vote

Using "pmount" you can.

by
Contributions licensed under CC0
...