Automating remote management via ssh/scp

Revision as of 18:32, 22 August 2013 by WikiSysop (talk | contribs) (correct typo)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

It is possible to automate configuration changes to Mesh Potatoes via the command line using ssh and scp.

Automate authentication

The first step is to set up automatic authentication by storing your ssh key on the Mesh Potato. Follow these steps

 $ ssh-keygen -t rsa
 Generating public/private rsa key pair.
 Enter file in which to save the key (/home/username/.ssh/id_rsa): 

Press return to leave the passwd blank.

 Enter passphrase (empty for no passphrase): 
 Enter same passphrase again: 
 Your identification has been saved in /home/username/.ssh/id_rsa.
 Your public key has been saved in /home/username/.ssh/

Copy your local public key to the remote server. Replace with the IP address of your Mesh Potato.

 $ scp ~/.ssh/ root@

Now you can ssh to the remote server without entering your password. Keep in mind that all someone needs to login to the remote server, is the file on your local machine ~/.ssh/id_rsa, so make sure it and the machine are secure.

Set the IP address of your MP

Here is a simple script that you can use to quickly set the IP address of your MP via ssh/scp.


if [[ ! ("$#" == 1 ) ]]; then 
    echo 'Please pass a number between 1 and 254 inclusive'
    exit 1
remcom="uci set network.lan.ipaddr=192.168.2.$1 && uci commit network && reboot"
secure="-o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null"
/usr/bin/ssh $secure root@ $remcom

The above example assumes that is the C-class range you wish to use on your network. It also assumes that you are communicating with the default IP address of a newly flashed MP. The StrictHostKeyChecking setting stops ssh/scp from throwing up an error if this is not the first time you have flashed the MP.