Error after setting SUID bit
Hello,
I write my ros node, which called zero_node and I need to run this node with root rights. For that I changed owner:
sudo chown root zero_node
and set SUID bit:
sudo chmod +s zero_node
But when I run my node, I get this error: "./zero_node: error while loading shared libraries: libxmlrpcpp.so: cannot open shared object file: No such file or directory"
If I run it withou SUID bit everything works fine, but without root rights of course. Do you have any ideas what I am doing wrong or maybe another ways to run ros node with root rights?
It's likely setting the
SUID
bit causes the executable loader to sanatise the environment before starting the binary.As
libxmlrpcpp.so
is not on the sanatised linker load path (ie: library search path), it cannot be found, and thus your binary cannot be started.Interesting, and what should I done to solve this problem?
Not run things as
root
. That's typically not a good idea.can you clarify why?
There may be other ways to achieve what you need to do, but without more information we cannot suggest any.
Also note: this is not a ROS problem, but a general system configuration one.
It's likely any binary which (tries to) link(s) libraries in locations not on the default linker search paths run into this problem when trying to run them as
root
(either directly or viasetuid
).Sorry, I had to clarify what I am doing. I am writing a rosnode that launches several other nodes and tracks their topics. In particular, I start a lidar node, but for this node to work, the permissions on /dev/ttyUSB0 must be changed. In the future, I want to start my node with a daemon and that node will run autonomously, which means I won't be able to enter the password for chmod every time I start my node. I have one solution - to allow the sudo chmod command to run without a password, but I think this is not a good idea from a security standpoint. And the second solution is to change the owner of my binary and set the SUID bit, but that doesn't work. So, I would really appreciate it if you can help me with this problem and suggest a better solution.
After your last comment this appears to be a clear example of an xy-problem.