ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

can't use sudo rosbag

asked 2019-08-13 22:00:48 -0600

Elite gravatar image

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 <module> import rosbag ImportError: No module named rosbag"" How should I config env?

edit retag flag offensive close merge delete



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

gvdhoorn gravatar image gvdhoorn  ( 2019-08-14 01:25:49 -0600 )edit

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

Elite gravatar image Elite  ( 2019-08-14 02:49:20 -0600 )edit

2 Answers

Sort by » oldest newest most voted

answered 2019-08-14 03:17:52 -0600

ct2034 gravatar image

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.bashin 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

edit flag offensive delete link more

answered 2019-08-14 08:41:27 -0600

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.

edit flag offensive delete link more

Question Tools

1 follower


Asked: 2019-08-13 22:00:48 -0600

Seen: 513 times

Last updated: Aug 14 '19