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

link|improve this question

feedback

2 Answers

up vote 7 down vote accepted

Just use ssh:

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

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.

link|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
feedback

Your Answer

 
or
required, but never shown

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