Pergunta

I'm looking for a fast and easy method to remote shell to my raspberry pi (with out password require and encrypted like ssh ) because my project require running simple command to raspberry pi many times / a second, any suggest ideas? update: Method must be used in C++

Foi útil?

Solução

Raw TCP sockets. It's hard to get simpler than that.

Server side:

#!/bin/bash
mkfifo /tmp/fifo.$$
netcat -l -p 12345 < /tmp/fifo.$$ | sh - &> /tmp/fifo.$$
rm /tmp/fifo.$$
  • Create a named pipe
  • Listen on port 12345. On connection, read from the pipe and write to stdout.
  • Redirect stdout of netcat to a shell that writes to the pipe. Basically this creates a netcat <> sh duplex.

Client side: netcat ip.address 12345

  • Takes commands on stdin
  • Output on stdout

The client can also be implemented in C++ by using sockets. Boost.Asio iostreams are pretty straightforward. http://www.boost.org/doc/libs/1_55_0/doc/html/boost_asio/example/cpp03/iostreams/daytime_client.cpp

#include <boost/asio.hpp>
boost::asio::ip::tcp::iostream s("ip.address", "12345");
s << "command\n";
s >> output;
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top