Require password when usb plugged in

Saman_kurdi

New Member
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
 


JulienCC

Active Member
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.
 

Saman_kurdi

New Member
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
 

Condobloke

Well-Known Member
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 ?
 

Saman_kurdi

New Member
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
 

JulienCC

Active Member
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:


Members online


Latest posts

Top