I wrote a bit of php code in my r-pi on which I installed raspbian. I would like know to protect this code from the possibility to being copied or read. I looking for a solution that crypt my directory (eg. /home/pi/myphpcode) from reading through raspbian and from reading through the SD insertion in a PC. Thanks.

  • I have provided a long answer covering this topic in another question. Give it some search and you will find it.
    – Marco Poli
    Aug 16, 2014 at 2:03

2 Answers 2


To keep someone from reading specific data on the SD card, use an encryption package to encrypt the data and then keep the decryption key off of the SD card. Of course, then application on your RPi will not be able to read the data, either. But your question did not state that as a requirement.

  • 1
    I try to explain my problem. I would like realise these two points: 1) if someone insert the r-pi's SD in a card reader (pc, etc.) he must not read anything. 2) if a user surf the raspbian OS and arrives in /home/pi/my_protected_dir he hould not be able to read the "my_protected_dir" content. Is there a solution? Thanks.
    – Tab
    Feb 16, 2014 at 18:37
  • 1
    My solution would satisfy your requirement. All you have to do is encrypt the data on the SD card and keep the encryption key off the SD card. Yet I suspect that what you really want to do is use the data on the RPi while keeping others from using it. What I'm trying to point out is that your question needs to be refined.
    – einnocent
    Feb 16, 2014 at 21:15
  • I found this tutorial but I wish to save the password in the grub instead of usb. Is it possible?
    – Tab
    Feb 17, 2014 at 17:45

You can store your home directory, or at least the encrypted program, using some dm-crypt based technique. dm-crypt will work on both physical devices (e.g. encrypted USB thumb drive) or a disk image, and since you are using Raspberry Pi you can use write a bit of code to store the cryptographic key in I2C EEPROM, sort of like a hardware decrypt dongle.

And if your code is not too big (<=2MB), you can store it in dm-crypt-enabled SPI DataFlash chips also.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.