Remotely Control Multiple Computers Using SSHSudo

Back in our SSH Basics article, we taught you how to use SSH to access a target computer and perform commands on that computer. We’re going to go a bit further in this article and then show you a very cool tool that can simplify a lot of your work with SSH.

You should remember how to:

    • Use SSH syntax
    • Open up a connection to that computer
    • Execute commands remotely

Just one more time, here’s the syntax for SSH:

ssh user@hostname

If you don’t remember what all the parts of that command do, head back to our Basic SSH article.

What’s a SuperUser?

We’ve mentioned it a couple times before, but I’d like to go into a bit more depth about what sudo is and what it can do for you.

First of all, let’s talk about what a superuser is. A superuser is an account on a computer that has all permissions. That is, they can do anything to any file or account on the computer – think of the superuser as the ultimate account.

Sudo allows you to execute a command as a superuser, meaning there are no restrictions on the command.

How do you use sudo?

Just type:

sudo command

It will prompt you for the root password, which you should then type in and hit enter (nothing will show up as you type). Assuming you typed the password right, the command will be executed without any restrictions. If you don’t know what the root password is, you should subscribe to our newsletter over in the sidebar – we tell you exactly how to get into the root account and change the password to whatever you want!

How can sudo be useful?

Sudo is useful when you want to perform commands like deleting files or changing passwords when you’re logged into an account that doesn’t have permission to perform those tasks.

You might be asking right now why you shouldn’t just be logged into a superuser all the time. That is not smart since any command you type will be immediately executed without any need for a password. That means that even if you type a very dangerous command (imagine you type the command to delete the contents of your hard drive), it will be executed.

I recommend staying on a normal user account and only using sudo when you need to.

Remotely Controlling Multiple Computers

We’re going to move to a slightly different topic now: using ssh to access multiple computers.

The slow way to do this is pretty simple: just run the same commands over and over again changing the target computer’s IP address and username, if applicable. This is fine if you’re running the same command on just two or three computers, but any higher than that and it starts to become an annoyance.

Introducing SSHSudo

There’s a tool that hugely simplifies this whole process: sshsudo.

Not only does sshsudo allow you to remotely perform commands on multiple computers, but it also allows you to painlessly run tasks via sudo on their computers.

Where might this be useful? Imagine you’re in a place where all the administrator account are the same, like a workplace or school. You could remotely control all the computers at once and run commands as the superuser on all of them! That’s pretty cool.

Installing SSHSudo

Installing SSHSudo is pretty easy. Just head to the website and download the file. It’s really small. Put the file in whatever directory you want. I’ll just put it in my home directory, so the path is:


Now we’re going to make the script executable. This is a vital step – without it, we won’t be able to run it. So type into Terminal:

chmod +x ~/Users/evansavage/sshsudo

Of course, replace the path to the file with where ever you put yours. Now you can run the script!

Using SSHSudo

Now here’s the part you’ve been waiting for – how to remotely control multiple computers!

Here’s the SSHSudo syntax (don’t worry, we’ll go through each part of it):

sshsudo -r -v [-u user] AccountList Command [arguments]

Whew! Let’s start at the beginning:

sshsudo is the start of the command – that’s the path to your ssh sudo file. I’ll show you how I recommend simplifying getting to the file in a minute, though.

-r is a modifier for the command sshsudo. You can choose to add it or not. If you do put it there, it will copy whatever script you’re running on the target computer to the target computer instead of running it remotely from your computer. This is useful if you want the script to execute more quickly, since the whole thing will be on the target computers.

-v is another modifier. It makes the shell display verbose output. This just means it will show more details of what is going on – you probably don’t need this.

-u is yet another modifier. This sets the default user for the script. If you do this, you don’t need to specify the username in the AccountList part of the command. If you choose not to specify the user, it will use whatever you put after -u. If you don’t put anything here, you will need to type the username for each computer you’re targeting. You may want to do that if you’re targeting a different account on each computer, but if you want to run a command as, say, admin on all those computers, this can be very useful.

AccountList is where you put the accounts. They should be formatted like this: user1@computer1,user2@computer2,user3@computer3 and so on. If you put a default username after the -u modifier, the format could be like this: computer1,computer2,computer3 etc. Alternatively, this could be the path to a file where you have the username and account syntax, one per line. Where I put computer1, computer 2, and computer 3, you should put the IP addresses, just like we did in the SSH Basics article.

Arguments is where you put the actual command that you want to run. If you need a refresher on what you can do here, go back to our first SSH article or check out How to Run AppleScript from the Command Line.

So a sample workflow would be:

  1. Open up Terminal
  2. Type cd ~/Users/evansavage and hit enter
  3. Type sshsudo -u admin,, say Im in your computer and hit enter

This will make the computers on the local network with IP addresses,, and all say “Im in your computer” out loud via the account name admin.

By using cd ~/Users/evansavage, I navigated to where my SSHSudo script was. That way when I execute the sshsudo command, I won’t need to type in a path to the file. Of course, change that to where you put your SSHSudo file

If you noticed, we left out the apostrophe in I'm, shortening it to Im. That’s because Terminal uses single quotes (the same character as an apostrophe) to call for other functions. If you type the command using I'm, leaving the apostrophe in, the command won’t run properly.

By the way, if you want to know more about pranking people by using SSH, sign up for our newsletter over in the right sidebar. It will send you a screencast after a couple days detailing exactly how to pull some awesome pranks on your friends.

I hope that by now, you’re realizing how many options you have. You can do so much with SSHSudo, from pranking a group of people to installing an app on multiple computers. Let us know in the comments if you have any questions about any of this, and we’ll be glad to answer them!


  1. Gautam Produturi



    Whenever I enter the ssh command, my computer prompts me to enter the password,(which I assumer is the target computer’s password) and subsequently poops this back out:

    =========================admin@ sudo say ‘hi’
    /Users/gautamproduturi/sshsudo: line 97: sshpass: command not found
    usage: mktemp [-d] [-q] [-t prefix] [-u] template …
    mktemp [-d] [-q] [-u] -t prefix
    /Users/gautamproduturi/sshsudo: line 101: sshpass: command not found
    rm: : No such file or directory

    What exactly is sshpass? What does it do? And why is it not being recognized?
    Any feedback would be appreciated… :)

    • david


      edit the script and change mktemp to mktemp -t tempssh

  2. Anonymous



    Hello, I was wondering if you could tell me how I would go about installing apps on computers through Terminal. What command would I type?

  3. Dude



    When I type this command “chmod +x ~/Users/username/sshsudo” it always says something about “No such files or directory” I can’t get past that. Help!

    • unknown


      … you need to change “username” for the short name of the account

  4. Alex.Proffitt



    How do I get rid of someone watching my computer using sudo i can’t find out their password

Leave a Reply