Did you know ... | Search Documentation: |
ssh_server.pl -- Embedded SSH server |
This module defines an embedded SSH server for SWI-Prolog on top of libssh. This module allows for a safe secondary access point to a running Prolog process. A typical use case is to provide a safe channal or inspection and maintenance of servers or embedded Prolog instances.
If possible, a login to the Prolog process uses a pseudo terminal to
realise normal terminal interaction, including processing of ^C to
interrupt running queries. If libedit
(editline) is used as the
command line editor this is installed (see el_wrap/0), providing
advanced command line editing and history.
The library currently support login to the Prolog process. Future versions may also use the client access and exploit the SSH subsystem interface to achieve safe interaction between Prolog peers.
A new connection creates a Prolog thread that handles the connection.
The new thread's standard streams (user_input
, user_output
,
user_error
, current_input
and current_output
) are attached to the
new connection. Some of the environment is shared as Prolog flags. The
following flags are defined:
TERM
environment variable passed from the client.
If a pseudo terminal is used and the ssh_term
flag is not dump
,
library(ansi_term) is connected to provide colorized output.
If a pseudo terminal is used and library(editline) is available, this library is used to enable command line editing.
Using ssh <options> <server> <command>
, <command>
is executed
without a terminal (unless the -t
option is given to ssh
to force
a terminal) and otherwise as a single Prolog toplevel command. For
example:
ssh -p 2020 localhost "writeln('Hello world')" Hello world true.
If the query is nondeterministic alternative answers can be requested in the same way as using the interactive toplevel. The exit code is defined as follows:
If a Prolor process with an embedded ssh server misbehaves it can be
forcefully aborted using the abort
command. This calls C abort()
as
soon as possible and thus should function even if Prolog is, for
example, stuck in a deadlock.
ssh -p 2020 localhost abort
ssh_server([port(Integer)])
. Options:
localhost
. Use *
to grant acccess from all network interfaces.etc/ssh
below the current directory and user_app_config('etc/ssh')
(normally ~/.config/swi-prolog/etc/ssh
). On failure it
creates, a directory etc/ssh
with default host keys and uses
these.authorized_keys_file
below)
The default is derived from the authorized_keys_file
option
and whether or not verify_password/3 is defined.auth_methods([public_key])
.
This file is in OpenSSH format and contains a certificate
per line in the format
<type> <base64-key> <comment>
The the file `~/.ssh/authorized_keys` is present, this will
be used as default, granting anyone with access to this account
to access the server with the same keys. If the option is
present with value []
(empty list), no key file is used.
etc/ssh
, use it.user_app_config('etc/ssh')
, use it.user_app_config('etc/ssh')
etc/ssh
int
signal to start the debugger. Notably
library(http/http_unix_daemon) binds this to terminates the process.color_term
. Note that we do not wish to inherit this as
the server may have different preferences.prolog
,
running the toplevel. Otherwise the argument is processed as a
single toplevel goal.?- capture_messages(debug). ?- trace(p/1).
The following predicates are exported from this file while their implementation is defined in imported modules or non-module files loaded by this module.
ssh_server([port(Integer)])
. Options:
localhost
. Use *
to grant acccess from all network interfaces.etc/ssh
below the current directory and user_app_config('etc/ssh')
(normally ~/.config/swi-prolog/etc/ssh
). On failure it
creates, a directory etc/ssh
with default host keys and uses
these.authorized_keys_file
below)
The default is derived from the authorized_keys_file
option
and whether or not verify_password/3 is defined.auth_methods([public_key])
.
This file is in OpenSSH format and contains a certificate
per line in the format
<type> <base64-key> <comment>
The the file `~/.ssh/authorized_keys` is present, this will
be used as default, granting anyone with access to this account
to access the server with the same keys. If the option is
present with value []
(empty list), no key file is used.