How to Use SSH Server

PHPoC can be set to an SSH server by using "set api ssh" command. The following example shows how to make an SSH server.

example of SSH server

$port = 22;                        // port number
$pid = pid_open("/mmap/tcp0");     // open TCP 0
pid_ioctl($pid, "set api ssh");    // set api to SSH
pid_bind($pid, "", $port);         // binding
pid_listen($pid);                  // listen TCP connection
    $state = pid_ioctl($pid, "get state");
    if($state == SSH_AUTH)
        $username = pid_ioctl($pid, "get ssh username");
        $password = pid_ioctl($pid, "get ssh password");
        echo "$username / $password\r\n";
        pid_ioctl($pid, "set ssh auth accept");
    if($state == SSH_CONNECTED)
        pid_send($pid, "Welcome to PHPoC SSH server\r\n");
        echo "Connection has been established!\r\n";


In the example above, PHPoC listens SSH connection from clients. After connection is established, it prints a username and a password from client. After that, it prints a welcome message and close the connection.

※ If you want to test this example, open a SSH client program on PC such as Tera Term and try connecting to PHPoC SSH server.

※ Authentication process including user identification should be implemented in user script.