225 votes

-bash: sudo: command not found

By default sudo is not installed on Debian, but you can install it. First enable su-mode: su - Install sudo by running: apt-get install sudo -y After that you would need to play around with users ...
Maksim Luzik's user avatar
  • 2,423
66 votes

Cannot run command as www-data using su

You are using su which is used to "switch user". Of course it won't work because www-data is a user account which cannot be used to login. You have told it: /usr/sbin/nologin. Maybe what you want is ...
fikr4n's user avatar
  • 931
47 votes

This user is currently not available - but allow to run script by this user

This is a typical use case for sudo. You're mixing sudo which allows running commands as another user and is highly configurable (you can selectively specify which user can run which command as which ...
cg909's user avatar
  • 7,112
40 votes
Accepted

Why is su world executable?

One point that is missing from ilkkachu's answer is that elevating to root is only one specific use for su. The general purpose of su is to open a new shell under another user's login account. That ...
Jim L.'s user avatar
  • 8,007
36 votes
Accepted

Cannot run command as www-data using su

Without debating su vs. sudo you can try adding -s /bin/sh to your command line. (I could not verify this option is available for jessie since the Debian manpages webserver isn't working: https://...
Mark Wagner's user avatar
  • 1,911
35 votes
Accepted

Why do all users start in /root instead of their home directories after su as root?

If you only give a username as argument, su changes user without changing much else: For backward compatibility, su defaults to not change the current directory and to only set the environment ...
Stephen Kitt's user avatar
30 votes
Accepted

"PermitRootLogin no" in sshd config doesn't prevent `su -`

PermitRootLogin only configures whether root can login directly via ssh (e.g. ssh [email protected]). When you login using a different user account, whatever you do in your shell is not influenced by ...
n.st's user avatar
  • 8,138
30 votes
Accepted

How to run command as different user

su -s /bin/bash -c "/usr/bin/echo -n foo" -g apache apache -s /bin/bash overrides nologin and allows to interpret value of -c option -c "/usr/bin/echo -n foo" allows to avoid using dash-starting ...
czerny's user avatar
  • 1,657
29 votes

How to run command as different user

sudo to the rescue! sudo -u <user> -g <group> -- echo -n foo
Lester Cheung's user avatar
27 votes

This user is currently not available - but allow to run script by this user

I found out the main problem is "/usr/sbin/nologin" in /etc/passwd When I want to execute su in this case, it must have -s /bin/bash inside, so for example: su -s /bin/bash -c '/home/someuser/secure....
peter's user avatar
  • 925
23 votes
Accepted

Does "sudo" rely on "su" in any way?

sudo doesn’t rely on su. Your setup prevents users from running anything because it doesn’t grant anything: it only prevents users from using /bin/su. You’d need NOPASSWD: ALL, !/bin/su or something ...
Stephen Kitt's user avatar
21 votes
Accepted

Su as root and run command in one line

You can use the -c option of su to pass a single command. su root -c 'sh /home/jay/script-that-needs-executing-as-root.sh'
Munir's user avatar
  • 3,332
21 votes
Accepted

debian su - and su $PATH differences?

Very recently (with version 2.32-0.2 of util-linux from 27 Jul 2018) Debian switched to a different su implementation, see bug 833256. The "new" su is from util-linux while the "old" one was contained ...
scai's user avatar
  • 10.8k
21 votes

Why is su world executable?

Historically (on non-GNU unices), it wasn't, or at least it manually checked if you were in a group called "wheel" permitted to su. The GNU version of su did not reproduce this functionality because ...
R.. GitHub STOP HELPING ICE's user avatar
20 votes

-bash: sudo: command not found

su and sudo are two different, but related commands. It is unusual for sudo not to be installed, but it may simply not be in your Path. Try /usr/bin/sudo command. If indeed sudo is not available, ...
DopeGhoti's user avatar
  • 76.1k
20 votes

X11 connection rejected because of wrong authentication

Since many people will come here with the same error message, not realising it's unrelated to the use of su, I'd like to point out that similar symptoms now occur for a very different reason: Anything ...
Heath Raftery's user avatar
18 votes
Accepted

How to harden su with dpkg-statoverride?

The purpose is to prevent ordinary users from running the su command (su is similar to sudo, the difference being that sudo executes one command, su starts a new session as a new user, which lasts ...
Nate from Kalamazoo's user avatar
18 votes
Accepted

adding a sudoer in debian

As root edit /etc/sudoers and place the following line: youruser ALL=(ALL) NOPASSWD:ALL after # Allow members of group sudo to execute any command %sudo ALL=(ALL:ALL) ALL In this way you ...
Ivan P's user avatar
  • 364
17 votes

Running GUI application as another (non-root) user

You could use X11 forwarding: ssh -XY otheruser@localhost your-gui-program-name-here
Michael F's user avatar
  • 281
17 votes
Accepted

Using "su - " to change user gives "No passwd entry for user"

The error message is pretty much self-explanatory. It says that the user jenkins has no entry in the /etc/passwd file i.e. the user does not exist in the system. When you do any user related ...
heemayl's user avatar
  • 56.3k
17 votes

Cannot run command as www-data using su

If you want not only execute one command, but switch to www-data in order to test some stuff for that user, this worked for me: sudo -u www-data sh It's a little bit shorter. Exit the session with [...
rundekugel's user avatar
17 votes
Accepted

In a `sudo find` command, how do I make sure that `-exec` command is run as normal user?

On systems that support it (GNU and quite a few others), you could do: sudo find /path/ -print0 | xargs -r0 process_paths xargs is not run under sudo, so it still has the original uids/gids and also ...
Stéphane Chazelas's user avatar
16 votes

adding a sudoer in debian

Following command is correct and enough but you need to completely logout the user and relogin to work . usermod -a -G sudo user
Omid Kosari's user avatar
15 votes
Accepted

Create a file as a different user and group

If you want to create a file as a specific user and group without using chown, you can use sudo and specify the user and group: sudo -u \#49 -g \#58 touch /tmp/something Note that the user you ...
Wildcard's user avatar
  • 36.5k
15 votes

How to run a command as apache

To switch to apache user su -s /bin/bash apache
Stack EG's user avatar
  • 1,636
14 votes
Accepted

su - user Vs sudo su - user

Just repeating both @dr01 and @OneK's answers because they are both missing some fine details: su - username - Asks the system to start a new login session for the specified user. The system will ...
Guss's user avatar
  • 12.7k
13 votes
Accepted

What exactly differentiates the root user from every other user?

Root is user 0 The key thing is the user ID 0. There are many places in the kernel that check the user ID of the calling process and grant permission to do something only if the user ID is 0. The ...
Gilles 'SO- stop being evil''s user avatar
12 votes

su vs sudo -s vs sudo -i vs sudo bash

su (switch user or substitute user) lets you switch user. su basically starts another shell instance with the privileges of the intended user. By default it switches you to the root user, if we want ...
Premraj's user avatar
  • 2,552

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