SSH & Remote Commands
Search Results
SSH & Remote Commands
SSH Basics
ssh user@hostname
Connect to remote server via SSH.
ssh root@192.168.1.100
ssh -p <port> user@hostname
Connect to SSH on custom port.
ssh -p 2222 user@server.com
ssh-keygen -t rsa -b 4096
Generate SSH key pair for authentication.
ssh-keygen -t rsa -b 4096 -C 'user@email.com'
ssh-copy-id user@hostname
Copy SSH public key to remote server.
ssh-copy-id admin@server.com
scp <file> user@hostname:<path>
Secure copy files to remote server.
scp app.zip user@server:/home/user/
rsync -avz <source> user@hostname:<dest>
Synchronize files/directories to remote server.
rsync -avz ./website/ user@server:/var/www/
SSH Key Management
ssh-add ~/.ssh/keyname
Add SSH private key to authentication agent.
ssh-add ~/.ssh/id_rsa
ssh-agent bash
Start SSH agent for managing private keys.
eval $(ssh-agent -s)
chmod 600 ~/.ssh/id_rsa
Set correct permissions for SSH private key.
chmod 600 ~/.ssh/id_rsa
ssh-add -l
List SSH keys currently loaded in agent.
ssh-add -l
SSH Security
sudo nano /etc/ssh/sshd_config
Edit SSH server configuration.
sudo nano /etc/ssh/sshd_config
sudo systemctl restart sshd
Restart SSH service after config changes.
sudo systemctl restart sshd
ssh -i <keyfile> user@hostname
Connect using specific private key file.
ssh -i ~/.ssh/server_key user@server.com
ssh -L <local_port>:localhost:<remote_port> user@hostname
Create SSH tunnel for port forwarding.
ssh -L 8080:localhost:80 user@server.com
ssh -v user@hostname
Connect with verbose output for debugging SSH issues.
ssh -v user@server.com
sudo ufw allow OpenSSH
Allow SSH through UFW firewall.
sudo ufw allow OpenSSH
sudo fail2ban-client status sshd
Check fail2ban SSH protection status.
sudo fail2ban-client status sshd
sshd -T
Display active SSH server configuration.
sudo sshd -T | grep Port
Remote Sessions
tmux new -s session_name
Create new tmux session for persistent remote work.
tmux new -s development
screen -S session_name
Start screen session for detached remote work.
screen -S server_maintenance
sftp user@hostname
Connect to remote server using SFTP for file transfer.
sftp admin@server.com
ssh user@host 'bash -s' < local_script.sh
Execute local script on remote server via SSH.
ssh user@server 'bash -s' < deploy.sh
Advanced Tunneling
ssh -R <remote_port>:localhost:<local_port> user@hostname
Create reverse SSH tunnel from remote to local.
ssh -R 8080:localhost:3000 user@server.com
ssh -D <local_port> user@hostname
Create SOCKS proxy tunnel through SSH.
ssh -D 1080 user@server.com
ssh -N -f -L <local_port>:localhost:<remote_port> user@hostname
Create background SSH tunnel without shell.
ssh -N -f -L 5432:localhost:5432 user@db-server.com