Ssh and scp

From Notepedia
Jump to: navigation, search

SSH Tunneling

Tunnelling if ssh is running on port 22

ssh -g -L 4321:localhost:80 [email protected]

Tunnelling if ssh is running on port 2200

ssh -p 2200 -f [email protected] -L 2000:localhost:9091 -N

The service running on the remote host port of 9091 can now be accessed on localhost port 2000

  • -p Determines which port ssh is on (if it's not on default 22)
  • -f tells ssh to go into the background just before it executes the command.
  • -L 2000:localhost:9091 is in the form of -L local-port:host:remote-port. If tunnelling to another host inside the tunnel is required then change "localhost".
  • -N instructs OpenSSH to not execute a command on the remote system.

SSH execute commands remotely

Using the ssh "-t" flag

ssh -p 2200 [email protected] -t "grep string /etc/bash.bashrc"

Secure copy through a tunnel

ssh -N -f -L 2123:<target>:22 repo.com.au

Then test:

ssh -p 2123 [email protected]

and execute:

scp -P 2123 [email protected]:/var/lib/firebird/backup/20100820.1200.hourly.fbk* .