johnnyo1012
Posts: 23
Joined: Mon Jul 10, 2017 4:04 pm

Password Protect SD Card?

Tue Jul 11, 2017 2:15 am

Hi, is it possible to password protect the sd card?

User avatar
CarlRJ
Posts: 599
Joined: Thu Feb 20, 2014 4:00 am
Location: San Diego, California

Re: Password Protect SD Card?

Tue Jul 11, 2017 2:55 am

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.)

johnnyo1012
Posts: 23
Joined: Mon Jul 10, 2017 4:04 pm

Re: Password Protect SD Card?

Wed Jul 12, 2017 4:16 pm

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.

scotty101
Posts: 3680
Joined: Fri Jun 08, 2012 6:03 pm

Re: Password Protect SD Card?

Wed Jul 12, 2017 5:09 pm

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.
Electronic and Computer Engineer
Pi Interests: Home Automation, IOT, Python and Tkinter

User avatar
mikronauts
Posts: 2717
Joined: Sat Jan 05, 2013 7:28 pm
Contact: Website

Re: Password Protect SD Card?

Wed Jul 12, 2017 5:31 pm

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.
http://Mikronauts.com - home of EZasPi, RoboPi, Pi Rtc Dio and Pi Jumper @Mikronauts on Twitter
Advanced Robotics, I/O expansion and prototyping boards for the Raspberry Pi

johnnyo1012
Posts: 23
Joined: Mon Jul 10, 2017 4:04 pm

Re: Password Protect SD Card?

Wed Jul 12, 2017 5:34 pm

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?

User avatar
mikronauts
Posts: 2717
Joined: Sat Jan 05, 2013 7:28 pm
Contact: Website

Re: Password Protect SD Card?

Wed Jul 12, 2017 5:56 pm

Google "usb protection dongle"
http://Mikronauts.com - home of EZasPi, RoboPi, Pi Rtc Dio and Pi Jumper @Mikronauts on Twitter
Advanced Robotics, I/O expansion and prototyping boards for the Raspberry Pi

NotRequired
Posts: 191
Joined: Sat Apr 29, 2017 10:36 am
Location: Denmark

Re: Password Protect SD Card?

Wed Jul 12, 2017 6:04 pm

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.
Please do not ask questions in private messages, they will not help others.

johnnyo1012
Posts: 23
Joined: Mon Jul 10, 2017 4:04 pm

Re: Password Protect SD Card?

Wed Jul 12, 2017 7:07 pm

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?

W. H. Heydt
Posts: 10770
Joined: Fri Mar 09, 2012 7:36 pm
Location: Vallejo, CA (US)

Re: Password Protect SD Card?

Wed Jul 12, 2017 7:55 pm

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?

johnnyo1012
Posts: 23
Joined: Mon Jul 10, 2017 4:04 pm

Re: Password Protect SD Card?

Wed Jul 12, 2017 8:15 pm

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.

rpiboy
Posts: 110
Joined: Mon Mar 20, 2017 8:39 pm

Re: Password Protect SD Card?

Wed Jul 12, 2017 9:13 pm

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.

asavah
Posts: 362
Joined: Thu Aug 14, 2014 12:49 am

Re: Password Protect SD Card?

Wed Jul 12, 2017 9:24 pm

@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.

mattmiller
Posts: 2102
Joined: Thu Feb 05, 2015 11:25 pm

Re: Password Protect SD Card?

Wed Jul 12, 2017 9:42 pm

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 :)

mattmiller
Posts: 2102
Joined: Thu Feb 05, 2015 11:25 pm

Re: Password Protect SD Card?

Wed Jul 12, 2017 9:44 pm

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 :)

johnnyo1012
Posts: 23
Joined: Mon Jul 10, 2017 4:04 pm

Re: Password Protect SD Card?

Thu Jul 13, 2017 1:37 am

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

W. H. Heydt
Posts: 10770
Joined: Fri Mar 09, 2012 7:36 pm
Location: Vallejo, CA (US)

Re: Password Protect SD Card?

Thu Jul 13, 2017 2:00 am

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.

i486
Posts: 172
Joined: Sun Aug 28, 2016 3:41 pm
Location: BG

Re: Password Protect SD Card?

Thu Jul 13, 2017 7:42 am

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

User avatar
RaTTuS
Posts: 10415
Joined: Tue Nov 29, 2011 11:12 am
Location: North West UK

Re: Password Protect SD Card?

Thu Jul 13, 2017 8:14 am

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
How To ask Questions :- http://www.catb.org/esr/faqs/smart-questions.html
WARNING - some parts of this post may be erroneous YMMV

1QC43qbL5FySu2Pi51vGqKqxy3UiJgukSX
Covfefe

Allanvm
Posts: 1
Joined: Thu Jul 27, 2017 1:57 pm

Re: Password Protect SD Card?

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

johnnyo1012
Posts: 23
Joined: Mon Jul 10, 2017 4:04 pm

Re: Password Protect SD Card?

Thu Jul 27, 2017 3:54 pm

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.

Return to “General discussion”