Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

How can I run a command on a remote Unix machine without starting a interactive session?

share|improve this question

2 Answers 2

up vote 7 down vote accepted

Just use ssh:

ssh yourusername@yourserver.com "ls -l"
share|improve this answer

You could add a Subsystem entry to your sshd_config file, if you plan on running a specific command regularly.

Subsystem samba-force-election /usr/bin/smbcontrol winbindd force-election

Then you can call it with the command 'ssh -s samba-force-election'.

Most systems have at least one defined:

Subsystem sftp /usr/lib/openssh/sftp-server

Which sftp, and scp call internally when they attempt to run.

share|improve this answer
    
Why is this better than a shell alias? –  Richard Hoskins Jul 19 '09 at 18:12
    
You can set it so that no-one has an interactive root shell, but allow them to run commands as root. –  Brad Gilbert Jul 19 '09 at 18:24
    
It will automatically work on all computers that need to run the command, and you won't have to update any of them if you need to change the command that is run. –  Brad Gilbert Jul 19 '09 at 18:25

Your Answer

 
discard

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.