Tag Info

Hot answers tagged

5

Use sudo -i to become root (with a root-shell) first instead. sudo is used to run commands as root, but > isn't a command, but a redirection inside the shell - neither of which is run by root. Say you run sudo cat foo > bar... cat is run as root, and can access and do anything - including opening "foo" even if it was owned by another user than you ...


4

init files, which run at system boot (or on demand) do two main things: they start daemons running they do various one-time-per-boot tasks, such as cleaning up or preparing files, setting network parameters, etc. In this case, the sudo init script does not start a daemon. Instead, it invalidates any cached credential files that may have been left around ...


3

sudo > different-file.txt launches sudo without arguments, and redirects standard output into different-file.txt. (Sudo probably outputs nothing to stdout when no arguments are given, so if you had permissions to overwrite you would probably truncate the file if it existed). Try cat /dev/null > different-file.txt instead (from a root prompt). Become ...


3

To empty a file as root, you can also use the truncate command: $ sudo truncate -s0 file.txt The -s0 sets the file's size to 0, effectively emptying it.


3

No it is not! (/home/usr/opt/android/platform-tools is not in the PATH within the sudo environment.) ${PATH} is evaluated by your shell before sudo is run, thus substituting the value of PATH before sudo is started, not the value within sudo. You are correct is suspecting the PATH. However you test gives a false answer because of the order of evaluation. ...


3

sudo has nothing to do with this little difference, the restriction is far closer to the kernel. You see, even though everyone has the right to execute the /sbin/ifconfig program, it does not mean that this program will have sufficient permissions to do its job with normal user privileges. Basically, with the UNIX permissions set, you have the right to ...


3

Removing vim-minimal was a mistake. If you intend to make use of sudo you have to have that package installed on Fedora. You can tell that sudo requires it like so: $ rpm -q --requires sudo | grep vim vim-minimal I'd suggest putting it back, and working around whatever the other issue actually was with vim. Fedora has always had excellent support when it ...


2

Ok, if anyone ends up in a similar situation, you can use pkexec yum install sudo. pkexec will let you enter your password in your OS's GUI. pkexec allows an authorized user to execute PROGRAM as another user. If username is not specified, then the program will be executed as the administrative super user, root. This helped: ...


2

It's difficult and confusing to get sudo and redirection together to work, but there is a more clear alternative: printf '' | sudo tee file.txt There is nothing special, actually: tee truncates the output files by default without -a option. It writes the input from stdin to the file. The input is the empty string, so the file is left empty. tee ...


2

sudo wants to run a program for you, but > file.txt does not contain a command. It is simply an implicit output redirect (incidentally, this doesn't work as given under tcsh, zsh and probably others). Even if you pass sudo a valid command, such as echo or : (the built in null command), what you are trying to do won't work as you expect. When you hit ...


2

I created a new file named new which is now owned by the root user as seen below. ls -lat new -rw-r--r-- 1 root root 42 Sep 9 13:37 new Now, I logged in as a normal user and from there I tried to erase the contents of this file using the below command. sudo sh -c " > /root/new" Now, I can verify that the contents are erased by logging back as root ...


2

Put the commands that you want to run as the other user into a separate file, user2commands, and then do sudo su - user < user2commands If you don’t want to have a separate file, consider: sudo su - user << EOF commands to be run as the other user ︙ EOF


2

Unless it's been explicitly disabled, you can ssh using your root user: ssh root@hostname.com


1

alias userYYY='sudo su userYYY -c "cd /a/path/that/only/userYYY/has/access; /bin/bash"'


1

If you want the entire script to run as another user, my usual technique for doing this is adding something similar to the following to the very top of the script: target_user="foo" if [ "$(whoami)" != "$target_user" ]; then exec sudo -u "$target_user" -- "$0" "$@" fi Note that I use sudo here and not su. su makes it stupidly difficult to pass arguments ...


1

From my personal experience this never worked. Figuring out a workaround creates more work and it may not work properly if you don't have root permissions.


1

In most configurations, sudo strips most environment variables. You can see the sudo configuration by running sudo -V as root (so sudo sudo -V as a user with sudo permissions). On Ubuntu, variables are stripped except from a small list, and EDITOR and VISUAL are not in the list to preserve. So when you run sudo somecommand, your per-user editor preferences ...


1

Scripts in /etc/init.d are there to allow the starting and stopping of services by systemd and similar init systems. They have a specific format and are what is actually called when you do something like service sudo stop So, the script you mention is simply a wrapper that can start or stop the sudo service. For more details, I suggest you read up on ...


1

The normal way works nicely for me: $ sudo -u test -n true sudo: a password is required $ echo $? 1 $ sudo -u test -n true >/dev/null 2>&1 $ echo $? 1 But if for whatever reasons it does not help for you, try these: $ { sudo -u test -n true ; } >/dev/null 2>&1 $ ...


1

I think he meant: $ who -am i which could (depending) be parsed the same as: $ who -am The "-a" lists all users currently logged in and "-m" filters that down to only those users (should really be one) who are associated with who's STDIN, which is to say it'll tell you who is logged in at your terminal. That's what you're looking for. $ who -am



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