Robotics StackExchange | Archived questions

can't use sudo rosbag

I can use rosbag by "rosbag record" and "sudo su" then "rosbag record" ,but I can't “sudo rosbag” I will get that:: ""Traceback (most recent call last): File "/opt/ros/melodic/bin/rosbag", line 34, in import rosbag ImportError: No module named rosbag"" How should I config env?

Asked by Elite on 2019-08-13 22:00:48 UTC

Comments

Can you clarify why you'd need to run rosbag (of all utilities) as root?

Asked by gvdhoorn on 2019-08-14 01:25:49 UTC

I add the ”rosbag“ into a service to achieve auto bag after boot. I use User=root ,I get "rosbag not found"

Asked by Elite on 2019-08-14 02:49:20 UTC

Answers

Firstly: I would strongly encourage you to NOT run any ROS tool as root. For example, the created bagfiles would then be owned by root.

But if you still want to do it, you have to source /opt/ros/melodic/setup.bash in your root shell (like for any other user). Then rosbag and everything should work fine. Although I would suggest trying creating a specific user for the task. (see https://askubuntu.com/questions/676007/how-do-i-make-my-systemd-service-run-via-specific-user-and-start-on-boot)

Asked by ct2034 on 2019-08-14 03:17:52 UTC

Comments

I'll chime in as well, that it is really bad to run this as root. It is perfectly possible to start the rosrun process under a different user from within an init script, in fact this is how this should be done.

There are some general linux instructions how to do this in this SO question.

running rosrun or even worse roslaunch with root permissions would be a huge security vulnerability.

Asked by PeteBlackerThe3rd on 2019-08-14 08:41:27 UTC

Comments