Skip to content

Latest commit

ย 

History

History
169 lines (123 loc) ยท 5.06 KB

File metadata and controls

169 lines (123 loc) ยท 5.06 KB

๐Ÿ”SSH Client Tools๐Ÿ’ป

  1. SSH: Secure remote access to servers. ๐Ÿ”’

    • Example: ssh user@hostname
  2. SCP: Secure file transfer between local and remote systems. ๐Ÿ“

    • Example: scp file.txt user@hostname:/remote/directory
  3. RSYNC: Sync files and directories securely between systems. ๐Ÿ”„๐Ÿ”

    • Example: rsync -avz /local/dir user@hostname:/remote/dir
  4. SFTP: Interactive file transfer over SSH. ๐Ÿ”„

    • Example: sftp user@hostname
  5. SSH Keys: Manage public/private key pairs for passwordless login. ๐Ÿ—๏ธ

    • Example: ssh -i ~/.ssh/id_rsa user@hostname

What is SSH (Secure Shell) ๐Ÿ”น

SSH (Secure Shell) is a cryptographic network protocol used for securely accessing and managing devices or systems over an unsecured network. It allows users to log into remote systems, execute commands, and transfer files securely. It encrypts all communications to prevent unauthorized access and eavesdropping.


Basic SSH Usage ๐Ÿ”น

๐Ÿ”ธ To connect to a remote system using the default username and port:

ssh 192.168.1.43

Explanation:

  • Connects to the remote system at IP 192.168.1.43 using the default SSH port (22) and username.

๐Ÿ”ธ To connect as a specific user on a remote system:

ssh root@192.168.1.31
ssh root@192.168.1.34

Explanation:

  • Specifies the username (root) to log in to the remote systems at 192.168.1.31 and 192.168.1.34.

๐Ÿ”ธ To specify a custom port for SSH (if the default port 22 has been changed):

ssh -l root -p 2222 192.168.1.34
ssh -p 2200 user@192.168.1.50

Explanation:

  • Uses the -p option to connect to a custom SSH port (2222, 2200), and the -l option specifies the username (root, user).

๐Ÿ”ธ To authenticate using a private key file (for secure login instead of a password):

ssh -i id_rsa_centos root@192.168.1.34
ssh -i ~/.ssh/id_ecdsa root@192.168.1.34

Explanation:

  • The -i option specifies the private key file (e.g., id_rsa_centos, id_ecdsa) for passwordless authentication.

๐Ÿ”ธ To enable verbose/debug mode for troubleshooting SSH connection:

ssh -v root@192.168.1.34
ssh -vvv -i ~/.ssh/id_rsa root@192.168.1.34

Explanation:

  • The -v option enables verbose output for debugging SSH connections. Use -vvv for even more detailed output.

๐Ÿ”ธ To execute a single command on the remote server without logging in:

ssh root@192.168.1.34 -p 22 'id'

Explanation:

  • Executes a single command (id) on the remote server without starting an interactive SSH session.

๐Ÿ”ธ To check the uptime (system running time) of a remote system:

ssh root@192.168.1.34 'uptime'

Explanation:

  • Executes the uptime command to display how long the remote system has been running.

๐Ÿ”ธ To read the hostname file on a remote system with an identity file and port:

ssh root@192.168.1.34 -p 22 -i ~/.ssh/id_rsa 'cat /etc/hostname'

Explanation:

  • Connects using a specific identity file (-i ~/.ssh/id_rsa) and port (-p 22), then reads the remote /etc/hostname file.

๐Ÿ”ธ To check the disk space usage on a remote machine:

ssh -i ~/.ssh/id_rsa root@192.168.1.34 "df -h"

Explanation:

  • Executes the df -h command to display the disk space usage in a human-readable format (e.g., MB, GB).

๐Ÿ”ธ To locally tunnel a remote server's web port from your local system:

ssh -L 8080:localhost:80 root@192.168.1.34

Explanation:

  • The -L option creates a local port forwarding, allowing you to access the remote web server (port 80) locally via port 8080.

๐Ÿ”ธ To connect to an internal machine through a gateway (jump host):

ssh -J root@gateway root@192.168.1.34

Explanation:

  • Uses the -J option to specify a jump host (gateway) to connect to the internal machine (192.168.1.34).

Conclusion on Basic SSH Usage ๐Ÿ”น

  1. Remote Access: SSH securely connects to remote systems.
    Example: ssh root@192.168.1.34

  2. Custom Ports & Users: You can specify ports and users for flexibility.
    Example: ssh -p 2222 root@192.168.1.34

  3. Key-Based Authentication: SSH allows passwordless logins using private keys.
    Example: ssh -i ~/.ssh/id_rsa root@192.168.1.34

  4. Debugging: SSH offers verbose mode for troubleshooting.
    Example: ssh -v root@192.168.1.34

  5. Remote Command Execution: Run commands on remote systems without logging in interactively.
    Example: ssh root@192.168.1.34 'uptime'

  6. System Info & File Access: SSH checks disk usage, uptime, and reads files remotely.
    Example: ssh root@192.168.1.34 'df -h'

  7. Port Forwarding: Access remote services via local ports.
    Example: ssh -L 8080:localhost:80 root@192.168.1.34

  8. Jump Host: SSH connects to an internal machine through an intermediary.
    Example: ssh -J root@gateway root@192.168.1.34


โšก