Page 1 of 1

Password Protect SD Card?

Posted: Tue Jul 11, 2017 2:15 am
by johnnyo1012
Hi, is it possible to password protect the sd card?

Re: Password Protect SD Card?

Posted: Tue Jul 11, 2017 2:55 am
by CarlRJ
There is some facility in the SD card spec for password protection, but to my knowledge*, there is no code in any of the Linux versions normally used on the PI to make use of the SD card's password protection capabilities. I've seen others ask about it numerous times, and I believe the answers are always negative. If someone can physically access the Pi, they can pull the microSD card and plug it into another computer and read the contents. It was designed to be a teaching and hobbyist computer.

*: (I'm just someone who has been experimenting with Raspberry Pi's, and following the forums here, for a couple years.)

Re: Password Protect SD Card?

Posted: Wed Jul 12, 2017 4:16 pm
by johnnyo1012
Thanks, I would like to password protect the sd card so someone can't plug the sd card into a computer and get the contents but if it is plugged in to a certain sd card it works.

Re: Password Protect SD Card?

Posted: Wed Jul 12, 2017 5:09 pm
by scotty101
This kind of question comes up almost weekly.

How would the SD card work on a Pi if it is password protected? What mechanism would be used to 'unprotect' the SD card? How would you enter the password?

More trouble than it is worth IMO.

Re: Password Protect SD Card?

Posted: Wed Jul 12, 2017 5:31 pm
by mikronauts
Can't be done.

Also would not protect against image copying.

If you are worried about copying, add an appropriate USB key dongle.
johnnyo1012 wrote:Thanks, I would like to password protect the sd card so someone can't plug the sd card into a computer and get the contents but if it is plugged in to a certain sd card it works.

Re: Password Protect SD Card?

Posted: Wed Jul 12, 2017 5:34 pm
by johnnyo1012
mikronauts wrote:Can't be done.

Also would not protect against image copying.

If you are worried about copying, add an appropriate USB key dongle.
johnnyo1012 wrote:Thanks, I would like to password protect the sd card so someone can't plug the sd card into a computer and get the contents but if it is plugged in to a certain sd card it works.

What do you mean USB dongle? Where can I get one to do that?

Re: Password Protect SD Card?

Posted: Wed Jul 12, 2017 5:56 pm
by mikronauts
Google "usb protection dongle"

Re: Password Protect SD Card?

Posted: Wed Jul 12, 2017 6:04 pm
by NotRequired
If a drive or memory card can be read by the Pi, then it can be read by anything else as well - this should be obvious. It is not possible for a drive or memory card to recognize the device which is accessing it and thereby decide wheter or not the contents should be made available to that device.

You may, however, encrypt the contents of a drive attached to a Pi, but the password (or key) must be stored on the Pi if the Pi is supposed to auto-mount the drive and this would be an unsecure sollution. The only secure way of attaching encrypted storage will require you to manually type in the password every time the storage is mounted.

Re: Password Protect SD Card?

Posted: Wed Jul 12, 2017 7:07 pm
by johnnyo1012
NotRequired wrote:If a drive or memory card can be read by the Pi, then it can be read by anything else as well - this should be obvious. It is not possible for a drive or memory card to recognize the device which is accessing it and thereby decide wheter or not the contents should be made available to that device.

You may, however, encrypt the contents of a drive attached to a Pi, but the password (or key) must be stored on the Pi if the Pi is supposed to auto-mount the drive and this would be an unsecure sollution. The only secure way of attaching encrypted storage will require you to manually type in the password every time the storage is mounted.
That would work. Every time I plug the sd card into a device it requires a passcode. How can I do what you said?

Re: Password Protect SD Card?

Posted: Wed Jul 12, 2017 7:55 pm
by W. H. Heydt
johnnyo1012 wrote:Hi, is it possible to password protect the sd card?
Every time this issue comes up, I feel that I must ask: What is it that you are trying so hard to protect? Is it code? Do you think your code is unique and that no one else will ever write a program to do the same thing? Is it data, such as names and social security numbers?

There are two major issues here. The first is the physical security of the actual device. If someone steals the Pi, SD card and all, then encryption *may* prevent reading the data...or it may not. It depends on how good your encryption is and who is trying to read it. The second is remote electronic access. In this case, if the files can be read by the Pi, then the intruder will be able to do so as well, so what you need to worry about is system security, not file or data security.

Then there is a semi-minor issue. You have to consider the cost (and your time is a cost) to secure the files against the value that will be lost if the files are stolen or compromised. Note that files that are stolen may still exist, so it's more a matter of the economic loss by there being someone else with the files.

Most of this comes down to this: What exactly are you trying to protect and what threats are you trying to protect it from, and why?

Re: Password Protect SD Card?

Posted: Wed Jul 12, 2017 8:15 pm
by johnnyo1012
W. H. Heydt wrote:
johnnyo1012 wrote:Hi, is it possible to password protect the sd card?
Every time this issue comes up, I feel that I must ask: What is it that you are trying so hard to protect? Is it code? Do you think your code is unique and that no one else will ever write a program to do the same thing? Is it data, such as names and social security numbers?

There are two major issues here. The first is the physical security of the actual device. If someone steals the Pi, SD card and all, then encryption *may* prevent reading the data...or it may not. It depends on how good your encryption is and who is trying to read it. The second is remote electronic access. In this case, if the files can be read by the Pi, then the intruder will be able to do so as well, so what you need to worry about is system security, not file or data security.

Then there is a semi-minor issue. You have to consider the cost (and your time is a cost) to secure the files against the value that will be lost if the files are stolen or compromised. Note that files that are stolen may still exist, so it's more a matter of the economic loss by there being someone else with the files.

Most of this comes down to this: What exactly are you trying to protect and what threats are you trying to protect it from, and why?

I just want to make a password or something to stop the average person from pluging the sd card into a computer, copying the files, and making copies. I am not trying to protect anything that would matter if it was compromised.

Re: Password Protect SD Card?

Posted: Wed Jul 12, 2017 9:13 pm
by rpiboy
If you do

Code: Select all

cat /proc/cpuinfo
There is a serial number unique to every Raspberry Pi.
You can write a script that gets and validates the serial number and if the number doesn't match,

Code: Select all

sudo reboot or sudo rm /
If an average person copies the sd card and put it in their PI all contents will be erased or automatic reboot on start up.

Code: Select all

while [ $SERIAL != "Your serial number" ]; do
      sudo rm / || sudo reboot
    done
I believe you will need to make it executable with sudo chmod +x

You can put the script in rc.local

Code: Select all

sudo sh /home/pi/serial.sh
or crontab -e

Code: Select all

@reboot /home/pi/serial.sh
which it will run on start up.

Re: Password Protect SD Card?

Posted: Wed Jul 12, 2017 9:24 pm
by asavah
@Op you should state what exactly you want to protect.
Is it whole sdcard with the OS or just some data on the sdcard (eg folder with documents) ?

It's possible to do both by using encryption.
This way even if someone plugs your sdcard into a linux computer with sdcard reader they won't be able to read it without your private key (password).

Whole sdcard (actually root partition, boot has to remain unencrypted) encryption is more envolved and complicated, certainly will cause severe perfomance penalty.
google: luks raspberry pi

Encrypting a random folder with data is easier
google: ecryptfs raspberry pi

Be aware that some guides may be outdated or just wrong.
Backup your data somewhere else before starting your experiments.

Re: Password Protect SD Card?

Posted: Wed Jul 12, 2017 9:42 pm
by mattmiller
There have been multiple threads on this subject (but they are tricky to find as forum search is diabolical so I'm not surprised your didn't find one)

The bottom line is no way (in any acceptable economic practical way) of protecting code on a Pi

Some may argue that I'm am factually wrong but it will be down to how do we define acceptable economic and practical :)

So don't take hope from the optimists :)

Re: Password Protect SD Card?

Posted: Wed Jul 12, 2017 9:44 pm
by mattmiller
One caveat - if this is to stop your 4 year old sibling from reading the code and selling it on the school yard - then there are many way of course :)

Re: Password Protect SD Card?

Posted: Thu Jul 13, 2017 1:37 am
by johnnyo1012
rpiboy wrote:If you do

Code: Select all

cat /proc/cpuinfo
There is a serial number unique to every Raspberry Pi.
You can write a script that gets and validates the serial number and if the number doesn't match,

Code: Select all

sudo reboot or sudo rm /
If an average person copies the sd card and put it in their PI all contents will be erased or automatic reboot on start up.

Code: Select all

while [ $SERIAL != "Your serial number" ]; do
      sudo rm / || sudo reboot
    done
I believe you will need to make it executable with sudo chmod +x

You can put the script in rc.local

Code: Select all

sudo sh /home/pi/serial.sh
or crontab -e

Code: Select all

@reboot /home/pi/serial.sh
which it will run on start up.

Thank You! This is what I need but I get the error, Can you help with the error? I am using your script I just filled in my serial number.

serial.sh: 2: [: !=: unexpected operator

Re: Password Protect SD Card?

Posted: Thu Jul 13, 2017 2:00 am
by W. H. Heydt
johnnyo1012 wrote: I just want to make a password or something to stop the average person from pluging the sd card into a computer, copying the files, and making copies. I am not trying to protect anything that would matter if it was compromised.
For that...get a case with a card cover.

Re: Password Protect SD Card?

Posted: Thu Jul 13, 2017 7:42 am
by i486
CarlRJ wrote:There is some facility in the SD card spec for password protection, but to my knowledge*, there is no code in any of the Linux versions normally used on the PI to make use of the SD card's password protection capabilities.
Have you tried this sdtool:

https://github.com/BertoldVdb/sdtool

Re: Password Protect SD Card?

Posted: Thu Jul 13, 2017 8:14 am
by RaTTuS
https://community.zymbit.com/t/encrypt- ... rry-pi/150 Encryption of your SDcard image

Note: I've not used this but it is the only way to do it on a RPi

Re: Password Protect SD Card?

Posted: Thu Jul 27, 2017 2:23 pm
by Allanvm
rpiboy wrote:
If you do
CODE: SELECT ALL

cat /proc/cpuinfo
There is a serial number unique to every Raspberry Pi.
You can write a script that gets and validates the serial number and if the number doesn't match,
CODE: SELECT ALL

sudo reboot or sudo rm /
If an average person copies the sd card and put it in their PI all contents will be erased or automatic reboot on start up.
CODE: SELECT ALL

while [ $SERIAL != "Your serial number" ]; do
sudo rm / || sudo reboot
done
I believe you will need to make it executable with sudo chmod +x

You can put the script in rc.local
CODE: SELECT ALL

sudo sh /home/pi/serial.sh
or crontab -e
CODE: SELECT ALL

@reboot /home/pi/serial.sh
which it will run on start up.

Thank You! This is what I need but I get the error, Can you help with the error? I am using your script I just filled in my serial number.

serial.sh: 2: [: !=: unexpected operator

I'm trying to do this, Have you find any solution to get it work? or someone else

Re: Password Protect SD Card?

Posted: Thu Jul 27, 2017 3:54 pm
by johnnyo1012
Allanvm wrote:
Thu Jul 27, 2017 2:23 pm
rpiboy wrote:
If you do
CODE: SELECT ALL

cat /proc/cpuinfo
There is a serial number unique to every Raspberry Pi.
You can write a script that gets and validates the serial number and if the number doesn't match,
CODE: SELECT ALL

sudo reboot or sudo rm /
If an average person copies the sd card and put it in their PI all contents will be erased or automatic reboot on start up.
CODE: SELECT ALL

while [ $SERIAL != "Your serial number" ]; do
sudo rm / || sudo reboot
done
I believe you will need to make it executable with sudo chmod +x

You can put the script in rc.local
CODE: SELECT ALL

sudo sh /home/pi/serial.sh
or crontab -e
CODE: SELECT ALL

@reboot /home/pi/serial.sh
which it will run on start up.

Thank You! This is what I need but I get the error, Can you help with the error? I am using your script I just filled in my serial number.

serial.sh: 2: [: !=: unexpected operator

I'm trying to do this, Have you find any solution to get it work? or someone else

I still haven't gotten this to work either. Let me know if you do.