Require password when usb plugged in

Saman_kurdi

New Member
Joined
Oct 27, 2019
Messages
3
Reaction score
1
Credits
0
Hello
I am beginner in linux
Is there anyone help me or refer to other post in the forum with this problem
I want a bash script that stops usb to run until you enter the password
I use linux ubuntu 18.04 LTS
 


There is one method described here that would probably work. Most things will work in Ubuntu that work in Mint, and vice versa. But this is not a Bash script, as you asked about. Maybe @JasKinasis will chime in and advise whether a Bash script is a good way to go.
 
I could give you one but you have to be more specific. If you disable all usb devices you will probably be unable to type passwords with you keyboard (probably USB, but could be something else).

Do you want to disable all USB or only USB storage ?

BTW the trick is to remove USB kernel modules.
 
Hello
I am beginner in linux
Is there anyone help me or refer to other post in the forum with this problem
I want a bash script that stops usb to run until you enter the password
I use linux ubuntu 18.04 LTS
I could give you one but you have to be more specific. If you disable all usb devices you will probably be unable to type passwords with you keyboard (probably USB, but could be something else).

Do you want to disable all USB or only USB storage ?

BTW the trick is to remove USB kernel modules.
thank you very much i want to protect usb ports with password when you plug in usb storage . I have laptop with ubuntu 18.04 installed
 
remember this is a removal usb key and thus is accessible readily without booting by simply plugging it in and mounting the FS if the files aren't encrypted. (in another computer the usb contents can be accessed if they are not encrypted)

Does this have any bearing on what you are trying to do ?
 
I don’t want to encrypt it
I want to disable usb ports when you insert any usb device the computer ask you a password to enable it
 
Here is what I suggest (didn't try myself) :

Create a "usb_policy" user with the password you want people to type to unlock USB
Bash:
adduser usb_policy

Add a sudo policy to this user for modprobe command
Bash:
echo "usb_policy    ALL = (root) /sbin/modprobe" >> /etc/sudoers

blacklist usb-storage module to prevent it from being activated at boot :
Bash:
echo "blacklist usb-storage" > /etc/modprobe.d/usb-policy.conf

Here is your bash script to ask for password and enable usb storage (make sure this is not run as root) :
Bash:
#!/bin/bash
su usb_policy
sudo modprobe usb-storage

And here is the script to disable USB storage, which must be run as root :
Bash:
#!/bin/bash
modprobe -r usb-storage

You could also add the latest script to sudoers as root for everyone, so that anyone can disable usb storage without having to type the password. But in this case make sure the file is owned by root and not writable by anyone (chmod a-w).
 
Last edited:

Staff online


Top