Sending commands to your PC from your Android phone.

You'll need: ConnectBot (free on the android market) on the phone, linux on the pc (I've used Ubuntu, but any will do).
First, make sure ssh is enabled PC side. If you PC has a public internet address you'll be able to send commands to it from the other side of the globe, otherwise, as my own setup, you can use the home wi-fi to control it from other rooms.
On the phone, using ConnectBot generate an RSA key pair.
Be sure to check "load at startup".
Then export the public key to your PC (by means of copy/paste via email for example).
On the PC, in your home dir of create a file named .ssh/authorized_keys as follows:

command="sudo shutdown -h now" ssh-rsa AAAAxxxxxc2EAAAADAQABAAAAgQDbTVtZxxxxRz+8EINWYbYvsD/dla30xxxx8LJiQrzgoLmFdTmM7FW+X//dmijMli8xxxx4yWVq/UTeGSDpc/drT4H3Csj7SSLnDksjxxxZqAZwTIncxxxxwu9VL5O6fqnxOWBh2+efnZV3+e2tbiGhqQ== username

You can put any command as you wish as the first token, and you'll need to paste your public key after ssh-rsa.
Create a new ConnectBot connection on the phone. Be sure to select public key authentication using the key you've generated before.
You can even create a shortcut on the phone desktop referring to the connection. This way with a single click on the phone you can issue commands on the pc.

No comments:

Post a Comment