1. Connect as Root with Disabled Public Key Authentication
ssh -o PubkeyAuthentication=no root@example-host
2. Connect with Private Key
ssh -i ~/.ssh/alice.pem alice@example.com
3. SSH Configuration File
3.1. View and Edit SSH Config File
cat ~/.ssh/config
3.2. Check Configuration Loading
ssh -v server
3.3. Directory Permissions
ls -ld -- .ssh*/
3.4. Multiple Private Keys in Config
cat ~/.ssh/config
4. SSH-Keyscan
ssh-keyscan -H 192.168.1.1 >> ~/.ssh/known_hosts
ssh-keyscan hostname
ssh-keyscan -p 10.0.0.0
ssh-keyscan -t rsa 10.0.0.0
5. SSH Troubleshooting
journalctl -u sshd
grep sshd /var/log/auth.log
grep sshd /var/log/secure
ssh -vvvvvv host
ssh -T user@example.com
ssh -vT user@example.com
ssh -G host
6. PuTTY Debug
Navigate to "Session" -> "Logging" -> "All session output" -> "SSH packet data"
7. SSH Key Management
7.1. Verify SSH Agent
eval "$(ssh-agent -s)"
7.2. Add SSH Private Key to Agent
ssh-add ~/.ssh/id_rsa
7.3. Change Passphrase
ssh-keygen -p
7.4. Test SSH Connection
ssh -T user@example.com
7.5. SSH over HTTPS
7.6. SSH Config for HTTPS
Create or edit ~/.ssh/config:
Host example.com
Hostname ssh.example.com
Port 443
Test the configuration:
ssh -T user@example.com
7.7. Fixing Permissions Issue
chmod 600 ~/.ssh/config
7.8. Multiple GitHub Accounts
Configure SSH and multiple accounts:
ssh-keygen -t rsa -b 4096 -C "email@examplePersonal"
ssh-keygen -t rsa -b 4096 -C "email@exampleWork"
Update ~/.ssh/config:
Host example-personal
Hostname ssh.examople.com
User user
Port 443
IdentityFile ~/.ssh/id_rsa_example-personal
Host example-work
Hostname ssh.example.com
User user
Port 443
IdentityFile ~/.ssh/id_rsa_example-work
7.9. SSH Copy-ID
ssh-copy-id -i ~/.ssh/id_rsa.pub user@remote-server
8. SSH Server Configuration
8.1. Directory Permissions
chmod 700 ~/.ssh
chmod 644 ~/.ssh/authorized_keys
chmod 644 ~/.ssh/known_hosts
chmod 644 ~/.ssh/config
chmod 600 ~/.ssh/id_rsa
chmod 644 ~/.ssh/id_rsa.pub
chmod 600 ~/.ssh/github_rsa
chmod 644 ~/.ssh/github_rsa.pub
chmod 600 ~/.ssh/mozilla_rsa
chmod 644 ~/.ssh/mozilla_rsa.pub
8.2. Copy Public Key Methods
ssh sheena@192.168.0.11 "chmod 700 .ssh; chmod 600 .ssh/authorized_keys"
cat ~/.ssh/id_rsa.pub | ssh username@remote_host "mkdir -p ~/.ssh && touch ~/.ssh/authorized_keys && chmod -R go= ~/.ssh && cat >> ~/.ssh/authorized_keys"
scp -pr ~/.ssh/id_rsa.pub user@example.com:/tmp
cat ~/.ssh/id_rsa.pub | ssh username@remote_host "mkdir -p ~/.ssh && cat >> ~/.ssh/authorized_keys"
ssh-copy-id -i mykey.rsa.pub -o "IdentityFile hostkey.rsa" user@target
8.3. Change SSH Listening Port
Edit /etc/ssh/sshd_config
:
Port 22
Port 2022
8.4. Troubleshoot SSH Permission Issues
chmod 700 ~/.ssh
chmod 600 ~/.ssh/id_rsa
9. SSH Agent Management
eval "$(ssh-agent -s)"
eval `ssh-agent`
SSH_AGENT_PID="$(pidof ssh-agent)" ssh-agent -k
kill -9 $(pidof ssh-agent)
eval "$(ssh-agent -k)"
9.1. Start SSH Agent in Background
exec ssh-agent bash
9.2. Add and List Identities
ssh-add
ssh-add -l
ssh-add -L
9.3. Delete Identities
ssh-add -D
ssh-add -d /home/user/.ssh/id_rsa
9.4. Lock and Unlock SSH Agent
ssh-add -x
10. SSH-Keygen and Permissions
ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
eval "$(ssh-agent -s)"
ssh-agent -s
ssh-add ~/.ssh/id_rsa
ssh-keygen -p
ssh -T user@example.com
ssh -T -p 443 user@ssh.example.com
chmod 700 ~/.ssh
chmod 644 ~/.ssh/authorized_keys
chmod 644 ~/.ssh/known_hosts
chmod 644 ~/.ssh/config
chmod 600 ~/.ssh/id_rsa
chmod 644 ~/.ssh/id_rsa.pub
chmod 644 ~/.ssh/authorized_keys2
chmod 644 ~/.ssh/known_hosts
11. SSH to Multiple Hosts via Bastion Host
Edit ~/.ssh/config:
Host private1
IdentityFile ~/.ssh/rsa_private_key
ProxyCommand ssh user@example -W %h:%p
Host bastion
IdentityFile ~/.ssh/example_rsa_key
12. Fixing Permissions Issue
chmod 600 privatekey.ppk
13. PuTTY Key Format
puttygen
14. Convert PuTTY PPK to OpenSSH Key on Windows
Putty Key Generator - Load private key
Putty Key Generator - Conversions - Export OpenSSH key
Note: Ensure to replace placeholder values like user, host, etc., with your actual information.
Table Of Commands
# | Command | Description |
---|---|---|
1 | ssh -o PubkeyAuthentication=no root@vg-ubuntu-02 | Connect as Root with Disabled Public Key Authentication |
2 | ssh -i ~/.ssh/alice.pem alice@ec2-23-22-230-24.compute-1.amazonaws.com | Connect with Private Key |
3 | cat ~/.ssh/config | View and Edit SSH Config File |
3.1 | ssh -v server | Check Configuration Loading |
3.2 | ls -ld -- .ssh*/ | Directory Permissions |
3.3 | cat ~/.ssh/config | Multiple Private Keys in Config |
4 | ssh-keyscan -H 192.168.1.162 >> ~/.ssh/known_hosts | SSH-Keyscan |
5 | journalctl -u sshd | SSH Troubleshooting |
6 | PuTTY Debug | Navigate to “Session” -> “Logging” -> “All session output” -> “SSH packet data” |
7 | eval "$(ssh-agent -s)" | Verify SSH Agent |
7.1 | ssh-add ~/.ssh/id_rsa | Add SSH Private Key to Agent |
7.2 | ssh-keygen -p | Change Passphrase |
7.3 | ssh -T git@github.com | Test SSH Connection |
7.4 | ssh -T -p 443 git@ssh.github.com | SSH over HTTPS |
7.5 | Create or Edit ~/.ssh/config | SSH Config for HTTPS |
7.6 | chmod 600 ~/.ssh/config | Fixing Permissions Issue |
7.7 | Configure SSH and Multiple Accounts | Multiple GitHub Accounts |
7.8 | ssh-copy-id -i ~/.ssh/id_rsa.pub user@remote-server | SSH Copy-ID |
8 | Directory Permissions | SSH Server Configuration |
8.1 | chmod 700 ~/.ssh | Copy Public Key Methods |
8.2 | chmod 644 ~/.ssh/authorized_keys | Change SSH Listening Port |
8.3 | Troubleshoot SSH Permission Issues | |
9 | eval "$(ssh-agent -s)" | SSH Agent Management |
9.1 | exec ssh-agent bash | Start SSH Agent in Background |
9.2 | ssh-add | Add and List Identities |
9.3 | ssh-add -D | Delete Identities |
9.4 | ssh-add -x | Lock and Unlock SSH Agent |
10 | ssh-keygen -t rsa -b 4096 -C "your_email@example.com" | SSH-Keygen and Permissions |
11 | Edit ~/.ssh/config | SSH to Multiple Hosts via Bastion Host |
12 | chmod 600 privatekey.ppk | Fixing Permissions Issue |
13 | Puttygen | PuTTY Key Format |
14 | PuTTY Key Generator – Conversions – Export OpenSSH key | Convert PuTTY PPK to OpenSSH Key on Windows |