Questions tagged [su]

GENERAL SU SUPPORT IS OFF-TOPIC. Support questions may be asked on https://superuser.com. su is a utility to run a shell or other command as another user (root by default).

su is a Unix/Linux utility that runs a shell or a specified command as another user. By default, the other user is root, and su, with , is one of the two common ways of obtaining administrator privileges. Calling su usually requires typing the target user's password.

su originally stood for “super user” (it was only for running a root shell), and became later known as “substitute user” (or “switch user” or a number of similar backronyms) when it started accepting the target user name as an argument.

For system administration questions, see the su tag on Super User (for non-professionals), Server Fault (for professionals), or Unix & Linux.

437 questions
151
votes
20 answers

How to pass the password to su/sudo/ssh without overriding the TTY?

I'm writing a C Shell program that will be doing su or sudo or ssh. They all want their passwords in console input (the TTY) rather than stdin or the command line. Does anybody know a solution? Setting up password-less sudo is not an option. expect…
n-alexander
  • 12,733
  • 11
  • 39
  • 43
147
votes
3 answers

How to run script as another user without password?

I have script.sh that must be run as user2. However, this script can only be run under user1 in my application. I would like the following command to run: su user2 -C script.sh but be able to run without password. I also want this to be very…
user788171
  • 13,907
  • 36
  • 87
  • 117
142
votes
9 answers

How do I use su to execute the rest of the bash script as that user?

I've written a script that takes, as an argument, a string that is a concatenation of a username and a project. The script is supposed to switch (su) to the username, cd to a specific directory based upon the project string. I basically want to…
Avery
  • 10,391
  • 15
  • 38
  • 53
97
votes
10 answers

How do you find the original user through multiple sudo and su commands?

When running a script via sudo or su I want to get the original user. This should happen regardless of multiple sudo or su runs inside of each other and specifically sudo su -.
evan
  • 11,329
  • 5
  • 34
  • 49
69
votes
3 answers

How to execute a group of commands as another user in Bash?

There are already some existing questions asked here about running commands as another user. However, the question and answers focus on a single command instead of a long group of commands. For example, consider the following…
Nathan Osman
  • 63,773
  • 66
  • 242
  • 344
40
votes
3 answers

OSX su command issue

So I cant get su command to work on a terminal. All I do is type "su" and press enter, it asks for the password and I enter my currently logged in user password. It always gives this error. I swear this used to work earlier, not sure what…
kapso
  • 10,921
  • 14
  • 53
  • 72
22
votes
5 answers

Changing to root user inside shell script

I have a shell script which needs non-root user account to run certain commands and then change the user to root to run the rest of the script. I am using SUSE11. I have used expect to automate the password prompt. But when I use spawn su - and the…
Deepti Jain
  • 1,741
  • 4
  • 16
  • 29
21
votes
2 answers

su postgres: Sorry?

i have a problem with my postgreSQL setup on my new Mac OSX Lion machine. I can't seem to connect to the service $ createuser -a -d _postgres Password: createuser: could not connect to database postgres: FATAL: password authentication failed for…
matt
  • 37,699
  • 99
  • 250
  • 390
17
votes
1 answer

Running Shell commands though java code on Android?

I've got an app that's supposed to use some shell commands to copy a file from the sdcard to /system/media/. It will require root, and I am testing on a rooted device. I'm using runtimes to execute the shell commands, but it's not working. Here's…
Ben
  • 758
  • 1
  • 8
  • 19
17
votes
2 answers

sh: parse_git_branch: command not found

I have root enabled on osx El Captain. I tried some of the solution already provided on stackoverflow and supersu but couldn't fix the error. I exported function parse_git_branch() to .bash_profile from .bash_prompt but I still get this error. I…
abhimanyuaryan
  • 3,470
  • 4
  • 36
  • 65
17
votes
10 answers

Auto boot when wall charger is plugged

I'm Developing an Android Application where it requireds 3 things:- To keep the App up an running for specific time and then phone will be off (Working Fine) When phone get charging from outlet, I want phone to power up automatically without…
Rohit
  • 821
  • 2
  • 8
  • 34
15
votes
3 answers

How does Android SuperUser app detect that an app requests root?

I'm writing an app that will use su to execute some commands in the linux kernel. I was wondering how SuperUser figures out that the application is asking for root privileges ? Also, are there any known ways (through obfuscation) in which this check…
asudhak
  • 2,439
  • 4
  • 18
  • 25
14
votes
3 answers

Linux C programming execute as user

I have an program which I run as root. I would like the program to execute another application as a normal user. I tried setgid() and it works, but I can't then go back to root or another user. The program for the time being is very simple; …
13
votes
4 answers

Running bash function in command of su

In my bash script, I execute some commands as another user. I want to call a bash function using su. my_function() { do_something } su username -c "my_function" The above script doesn't work. Of course, my_function is not defined inside su. …
Attila Zobolyak
  • 689
  • 1
  • 10
  • 15
13
votes
1 answer

What's the difference between `sudo -i -u user` and `sudo su - user`?

Both commands: sudo -i -u username sudo su - username Will log me in as username if I enter my password. Is there actually any difference between these commands?
Jan Dudulski
  • 753
  • 1
  • 7
  • 14
1
2 3
29 30