Avatar
Fernando Vásquez is an electronics engineer and software developer currently based in the world. He occasionally blogs about Python and Android programming.

SSH Cheat Sheet

Installation and basic usage

  • Install ssh server
sudo apt-get install openssh-server
sudo vi /etc/ssh/sshd_config
sudo /etc/init.d/ssh restart
  • Run command on SSH
ssh $__USER__@$__HOST__ command
  • check network
netstat -tulpn
  • To not to close SSH, edit /etc/ssh/sshd_config with:
TCPKeepAlive no
ClientAliveInterval 30
ClientAliveCountMax 100
  • SCP with permissions
scp -p -r $__USER__@$__HOST__:$__SRC__ $__TARGET__
  • Use a specific key file
scp -i ~/.ssh/superkey -p 87 $__USER__@$__HOST__:$__SRC__ $__TARGET__
  • Generate RSA key
ssh-keygen -t rsa
cat .ssh/id_rsa.pub | ssh __USER__@__REMOTE__ 'cat >> .ssh/authorized_keys'
chmod 700 ~/.ssh
chmod 600 ~/.ssh/authorized_keys

SSH Tunneling

  • MySQL tunneling from remote server to your local computar:
ssh -L 3333:localhost:3306 __USER__@__REMOTE__
mysql -u __MYUSER__ -p -P 3333 -h 127.0.0.1 
  • Allows remote hosts to connect to local port 8080.
ssh -g -L 8080:localhost:80 root@$HOST

Is SSH slow?

  1. Add the following line to /etc/ssh/sshd_config:
UseDNS no
  1. Still slow? add to /etc/ssh/ssh_config or ~/.ssh/config:
GSSAPIAuthentication no

References

all tags