Skip to content

SecureShell – SSH

  • TCP/IP port 22
  • sshd ‑ ssh server
    • package openssh-server
    • default sshd server config /etc/ssh/sshd_config
  • ssh ‑ ssh client
    • package openssh-client
    • default ssh client config /etc/ssh/ssh_config or ~/.ssh/config
Terminal window
# -v = verbose mode for debugging
# -4 = forces IPv4
# -6 = forces IPv6
# -i = specify the identity private key
# -p = port
ssh user@HOST
ssh -i private_key_file user@HOST
ssh HOST # if the ssh keys are already copied in the server
  • Generating the SSH keys ‑ ssh-keygen
Terminal window
# -t = type of key, dsa, ecdsa, ecdsa-sk, ed25519, ed25519-sk, rsa, rsa-sha2-512(DEFAULT)
# -b = Key length
# -f = Specify file to write to
# -C = comment
ssh-keygen -t rsa -b 4096
ssh-keygen -t ed25519
  • Securely copying public SSH keys ‑ ssh-copy-id
Terminal window
# -i = Specify the ssh key file
# -p = Port to login
ssh-copy-id -i ~/.ssh/id_rsa.pub user@HOST
  • scp & sftp
  • SSH Tunneling
Terminal window
# Any traffic send in the local machine 3306 is forwarded to 5432 port in the remote machine
ssh -L [local_port]:[destination_server_ip]:[remote_port] [username]@[hostname_or_IP]
ssh -L 3306:10.10.10.10:5432 user@hostname
# Remote port forward (any request direct in the remote machine port 3306 is forwarded to local machine 5432)
ssh -R [remote_port]:localhost:[local_port ssh_server_hostname]
ssh –R 3306:10.10.10.10:5432 user@hostname
OptionsDescription
-ispecify private key, when doing key-based auth
-pSSH port (default 22)
-venable verbose logging
-Cenable compression
-pSSH port (default 22)
Distro/OS/Package ManagerInstall Instruction
Centos/fedora(dnf, microdnf, rpm, yum)yum install openssh openssh-server
Debian/ubuntuapt install openssh-server openssh-client
Arch (pacman)pacman -Sy openssh
Alpine (apk-docker)apk add openssh