Remote Operations
SSH
ssh myUser@myTargetHostOpen a secure interactive session to the targeted host.
ssh myUser@myTargetHost myCommandRun a command in the targeted host.
ssh myUser@myTargetHost -N -L localhost:1212:myUnreachableHost:1212Create a local port forward.Allows local machine to access a port on a machine that is in another network.Scenario where local machine doesn't have access to
myUnreachableHost
p whilemyTargetHost
does.ssh myUser@myTargetHost -N -R 0.0.0.0:8080:localhost:80Create a remote port forward.Allows target machine to access a local machine port.Scenario where remote machine is not allowed to open connections to local machine, but the contrary is allowed.
SSH Flags
-pSpecify the port to connect to on the target.
-i myPrivateKeyFileConnect using private key (need that target trust public key beforehand).
-tForce pseudo-terminal allocation (e.g. allows connecting to a user that do not have a default shell).
-L myLocalBindAddr:myLocalPort:myUnreachableHost:myUnreachableHostPortLocal port forward.
-R myTargetHostAddr:myTargetHostPort:localhost:myLocalPortRemote port forward.
-D myBindAddr:myLocalPortDynamic port forward via specified port (ssh will act as a SOCKS proxy server).
-NDo not execute a remote command (useful for just forwarding ports).
-fRun in background (useful for just forwarding ports).
SCP
scp /path/to/myLocalFile.txt myUser@myTargetHost:/destination/path/Copy a local file to a remote host.
scp -r /path/to/myFolder myUser@myTargetHost:/destination/path/Copy a folder and its content to a remote host.
*scp -r /path/to/myFolder/ myUser@myTargetHost:/destination/path/myFolder/**Copy the content of a folder to a remote host.
SFTP
sftp myUser@myTargetHostCreate an SFTP session.
helpDisplay help.
pwdReturns remote current folder.
lpwdReturns local current folder.
lsLists folders and files in remote current folder.
llsLists folders and files in local current folder.
cdChanges remote directory.
lcdChanges local directory
getDownloads a file from server to client (-r for a directory).
putUploads a file from client to server (-r for a directory).
mkdirCreates a folder in remote.
lmkdirCreates a folder in local.
rmdirDeletes a folder.
rmDeletes a file.
exitExit SFTP session.
Key Management
Generate
ssh-keygen -t rsaGenerate a OpenSSH key pair (public and private keys).
Trust Keys
ssh-copy-id myUser@myHostCopy public key to target host (allows connecting with private key
-i
).