I have a sed script that changes some content in /etc/shadow. The actual change isn't important, I will put it just as an example:root@device:~ sed -i 's/root:\(.*\):0:0/root:\1:10:0/' /etc/shadowsed: can't create temp file '/etc/passwdH5HWP7': Permission deniedAs the output shows, there seems to be some permission error, but I am running the command as root.The sed being used is from BusyBox v1.22.1 on an embedded distribution.If I try the example in the home folder there is no error. Also, I can edit /etc/shadow normally via a text editor.Is sed creating files as a nonroot user?
Is sed run as a different user?
permissions;sed;root;busybox
The reason is probably that / (containing /etc) is a read only filesystem, but has a symlink for /etc/shadow, /etc/passwd, and other dynamic files that lands on a read-write filesystem.This will allow you to edit the shadow and passwd files directly. The sed -i fails because its implementation doesn't actually update in place. Rather, it creates a temporary file and writes the changes to that, and then replaced the original file with the temporary copy. The error message you are seeing says that sed can't write the (temporary) file /etc/passwdH5HWP7.Solution? Either don't use -i and control the temporary file's location yourself, or provide the -i flag with a filename. In both cases you need to provide a filename in a location with read-write access.