Skip to content

Latest commit

 

History

History
62 lines (41 loc) · 1.06 KB

File metadata and controls

62 lines (41 loc) · 1.06 KB

Secure Shell (SSH) Scripts

Connection Management

  • Connect to a remote host:

    ssh "<USER>"@"<TARGET>"
  • Test SSH connection with verbose output:

    ssh -v "<USER>"@"<TARGET>"
  • Execute a single command on the remote host:

    ssh "<USER>"@"<TARGET>" "<COMMAND>"
  • Remove a host key from known_hosts:

    ssh-keygen -R "<TARGET>"

Key Generation & Authentication

  1. Generate a new SSH key pair:

    ssh-keygen -t rsa-sha2-512
  2. Start the SSH agent and add your private key:

    eval "$(ssh-agent -s)"
    ssh-add ~/.ssh/id_rsa
  3. Retrieve the public key to add to Git or DevOps platforms:

    cat ~/.ssh/id_rsa.pub

File Transfer

  • Copy files to a remote host:

    scp "<LOCAL_FILE>" "<USER>"@"<TARGET>":"<REMOTE_PATH>"
  • Copy files from a remote host:

    scp "<USER>"@"<TARGET>":"<REMOTE_FILE>" "<LOCAL_PATH>"