Tag Info

Hot answers tagged

54

In details it works the following way: /usr/bin/sudo executable file has setuid bit set, so even when executed by another user, it runs with the file owner's user id (root in that case). sudo checks in /etc/sudoers file what privileges do you have and whether you are permitted to run the command you are invoking. Saying simply, /etc/sudoers is a file which ...


27

Use install instead of cp: sudo install -o belmin /etc/foo.txt ~/foo.txt


22

For the purposes you have described, the OS doesn't decide whether you need sudo to initially run the program. Instead, after the program starts running and then tries to do something that is not permitted by the current user (such as writing a file to /usr/bin to install a new command), the OS prevents the file access. The action to take on this condition ...


12

Sometimes the "Permission denied" message is due to filesystem permissions denying you write access, for example. The executable/tool simply checks if it the filesystem grants you enough permissions to do what you're about to do and throws an error if it's denied by the filesystem. Other times, the tool itself will check your user ID before allowing you to ...


12

With a POSIX-compatible cp you can sudo cp -p foo bar to preserve the following file metadata when copying: Access time Modification time User ID Group ID Mode If you want to set a different user JennyD's solution is best.


12

The whole point of sudo is to grant you someone's else privileges (usually root) without asking for this other account's password (unlike su). sudo is asking here for your password just to make sure a passerby won't misuse your unlocked terminal. Ubuntu and many other Linux and Unix OSes are granting an initial account created at installation time the ...


8

If you don't want to be challenged every time for your password then I'd recommend setting it to NOPASSWD in your /etc/sudoers file rather than hardcode your password in your logins. At least this way your primary login's password will remain intact and not be completely exposed in your .bashrc. To make this change run the command sudo visudo, and change ...


7

Yes. If your user account is compromised (as in someone/something else can run arbitrary commands in your name), then they can for instance modify your ~/.bashrc and add something like: alias sudo='sudo sh -c '\''install-my-backdoor; exec "$@"'\'' sh' so that when you run sudo apt-get update, it actually runs sudo sh -c 'install-my-backdoor; exec "$@"' ...


6

If you do: sudo cat /etc/foo.txt > ~/foo.txt Then ~/foo.txt will be open by the shell as you (so created with your credentials), and then sudo will be executed with its stdout redirected to that. In the end, the file will be owned by you. That kind of approach also helps limiting the things done by root. Here, root only uses his privilege to open ...


5

On Debian derived systems you can get the source (even as a non root user) using apt-get source provided sources.list has some deb-src entries. Otherwise it's stuck with downloading from the project source repository with standard tools. Once you've got that source then: ./configure --prefix=/home/me/mysoftware make make install Will work for most source ...


5

When running sudo under a user login session, will that change $PATH to be the root's $PATH during the running of sudo ? sudo will change $PATH variable, depend on your security policy. From sudo man page: PATH May be overridden by the security policy. In most system, env_reset option is enabled by default, this causes commands to be ...


5

Do you need to get an interactive login root shell? sudo -H -i from man sudo: -H The -H (HOME) option requests that the security policy set the HOME environment variable to the home directory of the target user (root by default) as specified by the password database. Depending on the policy, this may be the default ...


4

su and sudo are privileged programs. su changes (after successful authentication) the real and effective user and group id to that of the user you su to. Thus, su is similar to login. Note that su can be used to change to any user, not just root. sudo also changes the real and effective user and group ids. Up to this point su and sudo are similar (but ...


4

This is actually configuration-dependent. There is an env_reset option in sudoers that, combined with env_check and env_delete, controls whether to replace, extend, or pass through some or all environment variables, including PATH. The default behaviour is to have env_reset enabled, and to reset PATH. The value PATH is set to can be controlled with the ...


3

The answer to your question is: When you run a command with sudo, you run the command with elevated priviliges, that is root priviliges. You only have to type your normal user password because you (the user) has been added to sudoers file which gives you root priviliges.


3

Using sudo, you switch to another user. That's the whole point of the command. I assume you don't have any regular access to the first file, so you need to be another user (root in this case) to gain access. There's no way for sudo itself to manage that, since all sudo is doing is switching you to the other user to execute the command. You will need to ...


3

This happens because you're only running the echo command as root. The output redirect is handled by your (non-root) shell. To avoid this, don't use the shell's redirect and use an actual command to handle the writing: tee. What you want to do can be done as so: echo "xyz" | sudo tee test > /dev/null (if you don't redirect the output, tee will output xyz ...


3

I see the below information from here. When using sudo, use alias expansion (otherwise sudo ignores your aliases) alias sudo='sudo ' The reason why it doesn't work is explained here. Bash only checks the first word of a command for an alias, any words after that are not checked. That means in a command like sudo ll, only the first word (sudo) is ...


2

First the terminology. chmod is a program (and a system call) which alows changing permission bits of a file in a filesystem. sudo is a special program that allows running other programs with different credentials (typically with elevated privileges, most usually those of the root user). su is similar but less (read "not") configurable than sudo - most ...


2

As the 'Note:' hints at, this is usually caused by $PATH being set wrong. One way that happens is when you run dpkg -i without root; but that isn't the case here. An easy way to confirm the path is to run sudo -s, which tells sudo to run a shell instead of some other program. So you'll be landed at a root shell prompt. If you echo "$PATH", you'll likely ...


2

Edit your /etc/sudoers, add this line (or edit if it's existed): Defaults !tty_tickets fish somehow thinks command is from separated session. It's maybe due to tty's modification date as reported by stat is changing under fish. This was caused by fish's futimes() call See more details: fish issue #122 Disable futimes()


2

The Unix approach to groups that grant various sorts of access is quite primitive - it mostly just gives write (and possibly read) type permissions, to the relevant devices. So, for example, for dialout: faheem@orwell:/dev$ ls -lah | grep dialout crw-rw---T 1 root dialout 4, 64 Jul 22 22:45 ttyS0 crw-rw---T 1 root dialout 4, 65 Jul 22 22:45 ttyS1 ...


2

tl;dr Access is determined by the user who is running application, and sudo runs applications as different user. Full version: How does the OS know that a command needs sudo? It doesn't know. UNIX manages permissions not on application level but on filesystem level: permissions are granted for users to access specific files. Applications then are run ...


1

If you fiddled with your home directory, you needed root to get at the /home directory that contains it. Possibly your home now contains some stuff owned by something other than you, that the sudo obviates. An aggressive approach might be "sudo chown -R myname:users ~myname" A more cautious person might do "find ~myname ! -user myname" to look for such ...


1

First, disabling an account is usually done by setting the encrypted password to *, which is not the encrypted value of any string. I can't check right now, but I believe that's what Ubuntu does for root as well. So technically, there is no root password on Ubuntu. But sudo precedes Ubuntu; it was designed for systems where there certainly were root ...


1

From my look at man 5 sudoers, this might be intended for the case you distribute or share the same sudoers file over several machines, effectively making part of the file conditional on your hostname. So, you still have to have this sudoers file on 192.168.1.14, but it would not give you rights on .1.15.


1

So as you said yourself @krzysto, the solution is to add the following to the sudoers file beans ALL = (root,apache) NOPASSWD: /usr/bin/ksh -c /opt/renovations/var/script-*.sh beans ALL = (root,apache) NOPASSWD: /usr/bin/bash -c /opt/renovations/var/script-*.sh The next piece that is missing is to make sure that the group has execute permissions on the ...


1

TL;DR. I found out where the problem lies! I had to sleep some time between some of the partitioning tasks. Apparently I stumbled upon concurrency issues. In-depth: It looks like when a process completes, it doesn't mean that kernel has already completed it's role in the process (in case kernel has to do something after given process). In my case, that ...


1

This may be splitting hairs, but: to execute a file, you must have execute permission to the file and all the directories you navigate to get to the file.  So, if Tom has a program (do_interesting_stuff) in his home directory (/home/tom), and the directory is protected 700 (no access for anyone but owner) but the file is protected 755 (read and execute ...


1

You can also set the default PATH at /etc/sudoers edit the file using visudo and update the line to what ever you wish: Defaults secure_path = /sbin:/bin:/usr/sbin:/usr/bin



Only top voted, non community-wiki answers of a minimum length are eligible