Tag Info

New answers tagged

0

You could also take a look at privacyIDEA, which does not only provide you the possibility to use OTP for login to the machine (or for doing su/sudo) but it can also do OTP offline. Furthermore it is capable of managing your SSH keys. I.e. if you have many machines and several root users, all SSH keys are stored centrally. Thus it is easy to "revoke"/delete ...


0

If you use bash you can do here-doc $ su - user -s/bin/bash -c <<EOF export X=1 echo $X EOF That way you can execute many commands and keep the state inside a script. The same with sudo sudo -u user <<EOF your script here EOF


1

I have a workaround that seems to work. I created a separate ksh script that does all the db2 commands (establish a connection, then creates a table and grants permissions on it), and run that with any arguments needed. This means that it's running a set of commands in one su instance, despite using the -c part, so as to run it inside the script ...


0

Do you have an /etc/pam.d/su? On some systems, such as Debian Squeeze (at least), processing of limits configuration is disabled for su. For example, inside /etc/pam.d/su, you may see something like this: # Sets up user limits, please uncomment and read /etc/security/limits.conf # to enable this functionality. # (Replaces the use of /etc/limits in old ...


5

Pro tip: There is never really a good reason to run sudo su. To run a command as a different user, use sudo -u username command. If you want a root shell, run sudo -i or sudo -l. If you have activated the root account, you can also run su alone, but sudo su is just not useful. And yes, I know you see it everywhere. That said, sudo has the -E switch which ...


3

You can do it without calling login shell: sudo DUMMY=dummy su ec2-user -c 'echo "$DUMMY"' or: sudo DUMMY=dummy su -p - ec2-user -c 'echo "$DUMMY"' -p option make sudo preserve environment variables.


1

The variable expansion is performed by your interactive shell. You're running the command sudo with the arguments echo and tim. If you want the expansion to happen in the shell invoked by sudo, tell it to run a shell and pass the string echo $ME to that shell: sudo sh -c 'echo $ME' sudo removes most variables from the environment, because they can be a ...


-1

sudo just executes a command as another user. As a result current environment is used. However su changes user ID or become superuser. If you haven't set a password to root user, you run sudo su in order to become superuser. And when you become superuser, naturally environment is changed.


4

The environment variable expansion is done by the shell so the command you're actually running is "sudo echo tim". This is all done before sudo is run.



Top 50 recent answers are included