1

I ran sudo for qtcreator and now I can't do changes to my project_name.user.creator file. It says that it doesn't have permission. Also I ran ping command with sudo and now I can't use it without sudo. Do you know how to remove it?

ls -l /bin/ping
-rwxr-xr-x 1 root root 61240 Nov 10  2016 /bin/ping

ls -ld /usr/share/applications/*creator*
-rw-r--r-- 1 root root 354 Jul 21  2016 /usr/share/applications/qtcreator.desktop


ping 8.8.8.8
ping: socket: Operation not permitted sudo ping 8.8.8.8

sudo ping 8.8.8.8 [sudo] password for default:
PING 8.8.8.8 (8.8.8.8) 56(84) bytes of data.
64 bytes from 8.8.8.8: icmp_seq=1 ttl=58 time=1.22 ms
64 bytes from 8.8.8.8: icmp_seq=2 ttl=58 time=1.38 ms
64 bytes from 8.8.8.8: icmp_seq=3 ttl=58 time=1.29 ms
^C
--- 8.8.8.8 ping statistics --- 3 packets transmitted, 3 received, 0% packet loss, time 2002ms
rtt min/avg/max/mdev = 1.229/1.301/1.380/0.074 ms
default@martin-bogdanov:/home$
2
  • 1
    Please add to your question the output of running these commands in your terminal window ls -l /bin/ping and ls -ld *creator. May 11, 2018 at 11:11
  • 1
    The permissions for your ping executable are wrong (did you try to chmod it?). Run sudo chmod u+s /bin/ping (see here) May 11, 2018 at 11:39

1 Answer 1

2

Explanation

When you execute a command with sudo it just means that the user that is executing that command is root.

Therefore if the command you are executing creates any files, those files will have the owner and group owner fileds set to root.

Depending on the privileges of the files (also the executables), this may prevent other users to read/write/execute them.

Example

This is the output of ls -l /bin/ping on my computer:

-rwxr-xr-x 1 root root 61168 Feb 11  2017 /bin/ping

I will explain the -rwxr-xr-x and root root parts.

First character (-) represents the type of the file.
- Means a regular file.
d Means a directory.
and so on.

Next 3 characters (rwx) represent the actions that are allowed for the owner.

r Being able to read a file.
w Being able to write to a file.
x Being able to execute a file.

Next 3 characters (r-x) represent the actions that are allowed for the member of group owner group.

r Being able to read a file.
- Not able to write to a file.
x Being able to execute a file.

The last 3 characters (r-x) represents the actions that are allowed for users that are neither the owner nor members of the group owner group.

r Being able to read a file.
- Not able to write to a file.
x Being able to execute a file.

root root Means that the owner is the root user and the group owner is the group root.

General solution

To change the owner and group owner to your user account, you can always use

sudo chown username:groupname file_name

(groupname is by default same as username if you haven't change it manually.)

This will change the fields user to username and group owner to groupname for the file file_name.

Solution for specific ping problem

As both steeldriver and John WH Smith pointed out, you also need a setuid bit for the ping to work properly. Explanations can be found here and here.

Therefore, this will solve problem with ping:

sudo chmod u+s /bin/ping
4
  • ping 8.8.8.8 ping: socket: Operation not permitted sudo ping 8.8.8.8 [sudo] password for default: PING 8.8.8.8 (8.8.8.8) 56(84) bytes of data. 64 bytes from 8.8.8.8: icmp_seq=1 ttl=58 time=1.22 ms 64 bytes from 8.8.8.8: icmp_seq=2 ttl=58 time=1.38 ms 64 bytes from 8.8.8.8: icmp_seq=3 ttl=58 time=1.29 ms ^C --- 8.8.8.8 ping statistics --- 3 packets transmitted, 3 received, 0% packet loss, time 2002ms rtt min/avg/max/mdev = 1.229/1.301/1.380/0.074 ms default@martin-bogdanov:/home$
    – Martin
    May 11, 2018 at 11:19
  • 1
    @martin please put that in your question. It's useful information. You should format it as code by selecting the block and using the {} toolbar button. May 11, 2018 at 11:24
  • @Iskustvo thanks for the permissions explanation. I changed the ownership with chown of the project_name.creator.user file and now I can edit it without running qtcreator as root.
    – Martin
    May 11, 2018 at 11:40
  • 2
    On some distros, ping needs to be setuid root: see for example Why does ping need setuid permission? May 11, 2018 at 11:40

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .