0
$\begingroup$

Rosanswers logo

Hi guys,

I need to launch a specific node with root permissions. The reason is that I need to reset a USB device under specific circumstances (sometimes the device crashes and requires to be reset). Invoking the appropriate ioctl system call requires root permissions.

I'd like to launch that node through roslaunch. However it should be the only node to get into god mode.

The user ROS runs under is in a sudoer. Any idea on how to acheive that?

Thanks a lot!

Cheers, Hendrik


Originally posted by Hendrik Wiese on ROS Answers with karma: 1145 on 2014-05-15

Post score: 8


Original comments

Comment by lanyusea on 2014-05-15:
open a new terminal beside others, run >sudo -s ,then > roslaunch

Comment by Hendrik Wiese on 2014-05-15:
But this way all nodes run as root, don't they?

Comment by lanyusea on 2014-05-15:
I don't think so, you just root the current terminal session, i.e. the current node. others are still running without root.

Comment by Hendrik Wiese on 2014-05-15:
But I launch all my nodes with a single roslaunch call. What you supposedly mean is rosrun...

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

This can be done using the roslaunch launch-prefix option in the node tag. For example, if you user has passwordless sudo enabled, you could try:

<node pkg="my_pkg" type="my_node" name="my_super_node" launch-prefix="sudo"/>

If you don't want to set up passwordless sudo, and your node doesn't change very often, you could try setting the setuid bit on it, so that it runs as root even if started by a non-root user. The only trouble with this is that you'll have to reset the permissions whenever your node changes, and it generally won't be deployable through debs, and it will only work for compiled nodes; not for scripts.

cd devel/lib/my_pkg     # cd to the directory with your node
chown root:root my_node # change ownship to root
chmod a+rx my_node      # set as executable by all
chmod u+s my_node       # set the setuid bit

Note that both of these methods will unset LD_LIBRARY_PATH before executing your node (it's a security feature of glibc). This means that your node will either need to be statically compiled, or you'll need to turn on RPATH during the compilation process, so that the library search path is included in your executable rather than relying on the environment to be set up correctly.


Originally posted by ahendrix with karma: 47576 on 2014-05-15

This answer was ACCEPTED on the original site

Post score: 18


Original comments

Comment by Hendrik Wiese on 2014-05-16:
Sounds promising. Is it possible to use passwordless sudo even with a Python node? I'm okay with passwordless sudo.

Comment by ahendrix on 2014-05-16:
Yes, I think passwordless sudo with a python node should work. You may want to check that sudo is configured to pass the PYTHONPATH variable.

Comment by Wedigo on 2015-07-31:
I know this old question, but I got stuck on that issue for some days.

Could someone please be more specific how this is solved, especially concerning the staical compilation and turning on the RPATH?

Comment by ahendrix on 2015-08-08:
Have a look at https://gitlab.kitware.com/cmake/community/-/wikis/doc/cmake/RPATH-handling

Comment by Wedigo on 2015-08-10:
Thank you for the link.

I found a solution before you posted this. I added the needed environment variables to the sudo prefix in the .launch file. It works for now....

Comment by suforeman on 2017-01-20:
if using sudo as the launch-prefix, it may be necessary to use sudo -E to preserve the ROS environment variables.

Comment by Blupon on 2017-08-02:
hi ! how can I do the reverse of the command line 4 instructions set ? This broke my node and I don't understand the following documentation well enough to do the compilation part of the fix. Between, I'm trying to solve this

Comment by ahendrix on 2017-08-02:
You can remove the setuid bit with sudo chmod u-s my_node

Comment by muttidrhummer on 2019-01-18:
i noticed that when i close the launchfile in which i ran some nodes with sudo , the sudo nodes won't close at at all, any idea?

$\endgroup$

Your Answer

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