Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

When I run a script such as this:

ssh -t root@ '/tmp/'

where the script is defined as:

mkdir -p /data/workday/cred
chown -R myuser:myuser /data
su myuser -  # <------- NOTICE THIS ! ! ! ! 
rpm -Uvp --force --nodeps --prefix /data/place /data/RPMs/myrpm.rpm

Notice the above su command.

If I comment-out the su command, the script runs remotely and then my shell prompt returns to where I came from ( same server where I ran the ssh command above )

But leaving the script as listed above, causes the script to complete successfully but the shell prompt stays on the remote server.

How can I prevent that ? Making sure that the issuer of the rpm command is a different user than root just a listed ?

share|improve this question
asking the same question on multiple sites is discouraged: – glenn jackman Jan 23 '14 at 17:24
up vote 4 down vote accepted

Run the rpm command with sudo:

mkdir -p /data/workday/cred
chown -R myuser:myuser /data
sudo -u myuser rpm -Uvp --force --nodeps --prefix /data/place /data/RPMs/myrpm.rpm
share|improve this answer

su starts a shell. When you exit that shell, then the rpm command will execute. If you're changing user to execute the rpm command, then

su -c 'rpm -Uvp --force --nodeps --prefix /data/place /data/RPMs/myrpm.rpm'  myuser
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.