ssh Linux Command
Connects securely to a remote machine via the SSH protocol.
What does ssh do?
Connects securely to a remote machine via the SSH protocol.
Syntax
ssh [options] user@hostPractical example
ssh -p 2222 kali@192.168.1.100Questions about ssh
How do I connect to a remote server with SSH?
Use `ssh username@hostname` to connect. For example, `ssh user@192.168.1.100` connects to that IP address.
How do I connect on a non-standard port?
Use `ssh -p 2222 user@host` to connect on port 2222 instead of the default port 22.
How do I set up passwordless SSH login?
Generate keys with `ssh-keygen`, then copy to server with `ssh-copy-id user@host`. After that, SSH will use key authentication automatically.
How do I run a command on a remote server?
Use `ssh user@host 'command'` to execute a command on the remote server and return the output.
How do I debug SSH connection issues?
Use `ssh -vvv user@host` for verbose debug output. This shows each step of the connection process.
How do I change the SSH port on the server?
Edit /etc/ssh/sshd_config and change the Port line. Then restart SSH with `sudo systemctl restart ssh`.
How do I forward a local port to a remote server?
Use `ssh -L 8080:localhost:80 user@host` to forward local port 8080 to port 80 on the remote server.
How do I connect without checking the host key?
Use `ssh -o StrictHostKeyChecking=no user@host`. Only use this for testing; it disables host key verification.
Related Remote Access Commands
ssh-copy-idCopies your SSH public key to a remote server for key-based authentication.
scpSecurely copies files between local and remote hosts over SSH.
ssh-keygenGenerates SSH public/private key pairs for passwordless authentication.
rsyncEfficiently syncs files and directories between two locations (local or remote).
telnetConnects to a remote host via the Telnet protocol (unencrypted — prefer SSH).
ftpTransfers files to and from a remote host using the File Transfer Protocol.