SSH & Remote Commands

Try searching for: "list", "docker run", "git branch", "remove directory"
Search Results

SSH & Remote Commands

SSH Basics

ssh user@hostname

Connect to remote server via SSH.

Example: ssh root@192.168.1.100
ssh remote connection
ssh -p <port> user@hostname

Connect to SSH on custom port.

Example: ssh -p 2222 user@server.com
ssh port custom
ssh-keygen -t rsa -b 4096

Generate SSH key pair for authentication.

Example: ssh-keygen -t rsa -b 4096 -C 'user@email.com'
ssh keys security
ssh-copy-id user@hostname

Copy SSH public key to remote server.

Example: ssh-copy-id admin@server.com
ssh keys copy
scp <file> user@hostname:<path>

Secure copy files to remote server.

Example: scp app.zip user@server:/home/user/
scp copy transfer
rsync -avz <source> user@hostname:<dest>

Synchronize files/directories to remote server.

Example: rsync -avz ./website/ user@server:/var/www/
rsync sync backup

SSH Key Management

ssh-add ~/.ssh/keyname

Add SSH private key to authentication agent.

Example: ssh-add ~/.ssh/id_rsa
ssh agent keys
ssh-agent bash

Start SSH agent for managing private keys.

Example: eval $(ssh-agent -s)
ssh agent security
chmod 600 ~/.ssh/id_rsa

Set correct permissions for SSH private key.

Example: chmod 600 ~/.ssh/id_rsa
ssh permissions security
ssh-add -l

List SSH keys currently loaded in agent.

Example: ssh-add -l
ssh agent list

SSH Security

sudo nano /etc/ssh/sshd_config

Edit SSH server configuration.

Example: sudo nano /etc/ssh/sshd_config
ssh config security
sudo systemctl restart sshd

Restart SSH service after config changes.

Example: sudo systemctl restart sshd
ssh restart service
ssh -i <keyfile> user@hostname

Connect using specific private key file.

Example: ssh -i ~/.ssh/server_key user@server.com
ssh key authentication
ssh -L <local_port>:localhost:<remote_port> user@hostname

Create SSH tunnel for port forwarding.

Example: ssh -L 8080:localhost:80 user@server.com
ssh tunnel forwarding
ssh -v user@hostname

Connect with verbose output for debugging SSH issues.

Example: ssh -v user@server.com
ssh debug verbose
sudo ufw allow OpenSSH

Allow SSH through UFW firewall.

Example: sudo ufw allow OpenSSH
ssh firewall security
sudo fail2ban-client status sshd

Check fail2ban SSH protection status.

Example: sudo fail2ban-client status sshd
ssh fail2ban security
sshd -T

Display active SSH server configuration.

Example: sudo sshd -T | grep Port
ssh config test

Remote Sessions

tmux new -s session_name

Create new tmux session for persistent remote work.

Example: tmux new -s development
tmux session persistent
screen -S session_name

Start screen session for detached remote work.

Example: screen -S server_maintenance
screen session detached
sftp user@hostname

Connect to remote server using SFTP for file transfer.

Example: sftp admin@server.com
sftp transfer secure
ssh user@host 'bash -s' < local_script.sh

Execute local script on remote server via SSH.

Example: ssh user@server 'bash -s' < deploy.sh
ssh script remote

Advanced Tunneling

ssh -R <remote_port>:localhost:<local_port> user@hostname

Create reverse SSH tunnel from remote to local.

Example: ssh -R 8080:localhost:3000 user@server.com
ssh reverse tunnel
ssh -D <local_port> user@hostname

Create SOCKS proxy tunnel through SSH.

Example: ssh -D 1080 user@server.com
ssh socks proxy
ssh -N -f -L <local_port>:localhost:<remote_port> user@hostname

Create background SSH tunnel without shell.

Example: ssh -N -f -L 5432:localhost:5432 user@db-server.com
ssh tunnel background