How to make server via SSH remote command execution?
0x00 Foreword
I have a Pi, hanging from a service, but this service as long as there is no communication for a long time will have their own hang. Try to use crontab automatically restart every hour, sometimes still have to manually restart the service.
So, I would like simply to use every time you open a terminal when it got started.
But each time SSH, lost password, execute the command too much trouble, you can not just think of this done with a single command.
0x01 SSH command execution
Looked under the manual, execute commands by SSH, in fact, just add commands after the hostname would be finished.
ssh [email protected] reboot
0x02 free dense Login
Remote execution of commands ok, it would have to solve some secret free to sign up.
The SSH also has built-in tools can be resolved.
First by the host ssh-keygen
generates a public-private key pair
ssh-keygen
All the way round, then default on the public key stored in ~/.ssh/id_rsa.pub
the.
Then copying the public key of the server's ~/.ssh/authorized_keys
file
ssh-copy-id -i ~/.ssh/id_rsa.pub [email protected]
Then the server can be free-tight connection, remote execution of commands for Free adhesion.
But every time you turn a long list of commands or trouble, there is no way to complete a word of it?
0x03 command aliases
I do not know alias
how to translate, but the meaning is probably an alias.
Editing ~/.bashrc
, this file is automatically executed every time you open a terminal time.
In the end, add a
alias lalala="ssh [email protected] reboot"
Then just hit the terminal lalala
, the server restart.
Here is reboot
replaced by the command you want to execute it.