- If i already have a ssh connection established from system-source to system-destination, can i copy a file from system-source to system-destination within that ssh connection
Sim, man ssh_config
e dê uma olhada em ControlMaster
e ControlPath
:
ControlMaster
Enables the sharing of multiple sessions over a single network connection. When set to “yes”, ssh(1) will listen
for connections on a control socket specified using the ControlPath argument. Additional sessions can connect to
this socket using the same ControlPath with ControlMaster set to “no” (the default). These sessions will try to
reuse the master instance's network connection rather than initiating new ones, but will fall back to connecting
normally if the control socket does not exist, or is not listening.
Setting this to “ask” will cause ssh to listen for control connections, but require confirmation using the
SSH_ASKPASS program before they are accepted (see ssh-add(1) for details). If the ControlPath cannot be opened,
ssh will continue without connecting to a master instance.
X11 and ssh-agent(1) forwarding is supported over these multiplexed connections, however the display and agent
forwarded will be the one belonging to the master connection i.e. it is not possible to forward multiple displays
or agents.
Two additional options allow for opportunistic multiplexing: try to use a master connection but fall back to cre‐
ating a new one if one does not already exist. These options are: “auto” and “autoask”. The latter requires
confirmation like the “ask” option.
ControlPath
Specify the path to the control socket used for connection sharing as described in the ControlMaster section
above or the string “none” to disable connection sharing. In the path, ‘%L’ will be substituted by the first
component of the local host name, ‘%l’ will be substituted by the local host name (including any domain name),
‘%h’ will be substituted by the target host name, ‘%n’ will be substituted by the original target host name spec‐
ified on the command line, ‘%p’ the port, ‘%r’ by the remote login username, and ‘%u’ by the username of the user
running ssh(1). It is recommended that any ControlPath used for opportunistic connection sharing include at
least %h, %p, and %r. This ensures that shared connections are uniquely identified.
Adicione 2 destas linhas ao seu ~/.ssh/config
:
ControlMaster auto
ControlPath ~/.ssh/control:%h:%p:%r
saia de todas as conexões SSH existentes e faça uma nova conexão com o servidor. Agora, em uma segunda janela, a sessão scp
será encapsulada sobre a primeira.
Also, since i am connected to system-destination over ssh, is there way for me to list files on system-source?
O encaminhamento remoto de portas é o que você está procurando.
man ssh
:
-R [bind_address:]port:host:hostport
Specifies that the given port on the remote (server) host is to be forwarded to the given host and port on the
local side. This works by allocating a socket to listen to port on the remote side, and whenever a connection is
made to this port, the connection is forwarded over the secure channel, and a connection is made to host port
hostport from the local machine.
Port forwardings can also be specified in the configuration file. Privileged ports can be forwarded only when
logging in as root on the remote machine. IPv6 addresses can be specified by enclosing the address in square
braces.
By default, the listening socket on the server will be bound to the loopback interface only. This may be over‐
ridden by specifying a bind_address. An empty bind_address, or the address ‘*’, indicates that the remote socket
should listen on all interfaces. Specifying a remote bind_address will only succeed if the server's GatewayPorts
option is enabled (see sshd_config(5)).
If the port argument is ‘0’, the listen port will be dynamically allocated on the server and reported to the
client at run time. When used together with -O forward the allocated port will be printed to the standard out‐
put.
No servidor, na linha de comando ssh, crie um encaminhamento de porta remoto digitando:
-
~C
Enter -
-R 2302:localhost:22
Enter
você verá algo assim:
[user@server ~] $
ssh> -R 2302:localhost:22
Forwarding port.
então você pode listar os arquivos no cliente executando:
ssh localhost -p 2302 "ls"