Search code examples
pythonrootpermission-denieddd

dd command PERMISSION DENIED Python


I have used a command line to run a dd command in Python, however, whenever I try to actually run the command, I get:

dd: opening '/dev/sdb': Permission denied

I know I have to do some kind of root thing? And I only need a certain section of my code to run the dd command, so I don't need to 'root' the whole thing; but the whole 'root' concept confuses me...

Help would be HIGHLY appreciated!!


Solution

  • I know I have to do some kind of root thing?

    Indeed you do!

    If you are using linux, sudo is the idiomatic way to escalate your user's privilege.

    So instead invoke 'sudo dd if=/dev/sdb of=/dev/null' (for example). If your script must be noninteractive, consider adding something like admin ALL = NOPASSWD: ALL to your sudoers, or something similar.