Skip to content

Instantly share code, notes, and snippets.

@AliAryanTech
Forked from slowkow/ssh-tutorial.md
Created February 22, 2025 11:28
Show Gist options
  • Save AliAryanTech/a54621e44df2062f4d99a31b8064d121 to your computer and use it in GitHub Desktop.
Save AliAryanTech/a54621e44df2062f4d99a31b8064d121 to your computer and use it in GitHub Desktop.

Revisions

  1. @slowkow slowkow revised this gist Dec 15, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion ssh-tutorial.md
    Original file line number Diff line number Diff line change
    @@ -34,7 +34,7 @@ Save yourself a few keystrokes. Follow the steps below:

    2. If you would prefer to type `jupiter` (7 characters) rather than
    `[email protected]` (21 characters), create a config file
    `~/.ssh/config` on your laptopt, as shown below. You'll be able
    `~/.ssh/config` on your laptop, as shown below. You'll be able
    to use the `jupiter` alias with: `rsync`, `scp`, and `ssh`.
    ```
  2. @slowkow slowkow revised this gist Dec 15, 2014. 1 changed file with 3 additions and 2 deletions.
    5 changes: 3 additions & 2 deletions ssh-tutorial.md
    Original file line number Diff line number Diff line change
    @@ -34,11 +34,12 @@ Save yourself a few keystrokes. Follow the steps below:

    2. If you would prefer to type `jupiter` (7 characters) rather than
    `[email protected]` (21 characters), create a config file
    `~/.ssh/config` as shown below. You'll be able to use this alias
    with: `rsync`, `scp`, and `ssh`.
    `~/.ssh/config` on your laptopt, as shown below. You'll be able
    to use the `jupiter` alias with: `rsync`, `scp`, and `ssh`.
    ```
    # ~/.ssh/config
    Host jupiter
    User carl
    HostName myserver.com
  3. @slowkow slowkow revised this gist Dec 15, 2014. 1 changed file with 11 additions and 7 deletions.
    18 changes: 11 additions & 7 deletions ssh-tutorial.md
    Original file line number Diff line number Diff line change
    @@ -33,17 +33,15 @@ Save yourself a few keystrokes. Follow the steps below:
    ```

    2. If you would prefer to type `jupiter` (7 characters) rather than
    `[email protected]` (21 characters), run this Bash script on your laptop.
    You'll be able to use this alias with: `rsync`, `scp`, and `ssh`.
    `[email protected]` (21 characters), create a config file
    `~/.ssh/config` as shown below. You'll be able to use this alias
    with: `rsync`, `scp`, and `ssh`.
    ```bash
    #!/usr/bin/env bash
    cat >> ~/.ssh/config <<END
    ```
    # ~/.ssh/config
    Host jupiter
    User carl
    HostName myserver.com
    END
    ```
    At this point, you can connect to your server like this:
    @@ -70,6 +68,12 @@ Save yourself a few keystrokes. Follow the steps below:
    User carl
    ProxyCommand ssh -qX jupiter nc %h %p
    ```
    At this point, you can connect to `saturn` via `jupiter` like this:
    ```bash
    ssh saturn
    ```
    # Further reading
  4. @slowkow slowkow revised this gist Oct 18, 2014. 1 changed file with 6 additions and 0 deletions.
    6 changes: 6 additions & 0 deletions ssh-tutorial.md
    Original file line number Diff line number Diff line change
    @@ -46,6 +46,12 @@ Save yourself a few keystrokes. Follow the steps below:
    END
    ```
    At this point, you can connect to your server like this:
    ```bash
    ssh jupiter
    ```
    3. If you want a single command to do two steps:
    1. First, connect to a login server `jupiter`
  5. @slowkow slowkow revised this gist Oct 18, 2014. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions ssh-tutorial.md
    Original file line number Diff line number Diff line change
    @@ -32,9 +32,9 @@ Save yourself a few keystrokes. Follow the steps below:
    ssh [email protected]
    ```

    2. If you would prefer to type `jupiter` rather than `myserver.com`, run this
    Bash script on your laptop. You'll be able to use this alias with:
    `rsync`, `scp`, and `ssh`.
    2. If you would prefer to type `jupiter` (7 characters) rather than
    `[email protected]` (21 characters), run this Bash script on your laptop.
    You'll be able to use this alias with: `rsync`, `scp`, and `ssh`.
    ```bash
    #!/usr/bin/env bash
  6. @slowkow slowkow revised this gist Oct 13, 2014. 1 changed file with 17 additions and 3 deletions.
    20 changes: 17 additions & 3 deletions ssh-tutorial.md
    Original file line number Diff line number Diff line change
    @@ -46,8 +46,12 @@ Save yourself a few keystrokes. Follow the steps below:
    END
    ```
    3. If you want a single command to do two steps: (1) connect to a login server `jupiter`,
    and then connect to a work server `saturn`, configure your `~/.ssh/config` file as follows:
    3. If you want a single command to do two steps:
    1. First, connect to a login server `jupiter`
    2. Next, connect to a work server `saturn`
    Then configure your `~/.ssh/config` file as follows:
    ```
    # ~/.ssh/config
    @@ -59,4 +63,14 @@ Save yourself a few keystrokes. Follow the steps below:
    Host saturn
    User carl
    ProxyCommand ssh -qX jupiter nc %h %p
    ```
    ```
    # Further reading
    How to write your own config file:
    - http://www.cyberciti.biz/faq/create-ssh-config-file-on-linux-unix/
    All available configuration options:
    - http://linux.die.net/man/5/ssh_config
  7. @slowkow slowkow revised this gist Oct 12, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion ssh-tutorial.md
    Original file line number Diff line number Diff line change
    @@ -32,7 +32,7 @@ Save yourself a few keystrokes. Follow the steps below:
    ssh [email protected]
    ```

    2. If you would prefer to type `jupter` rather than `myserver.com`, run this
    2. If you would prefer to type `jupiter` rather than `myserver.com`, run this
    Bash script on your laptop. You'll be able to use this alias with:
    `rsync`, `scp`, and `ssh`.
  8. @slowkow slowkow revised this gist Oct 12, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion ssh-tutorial.md
    Original file line number Diff line number Diff line change
    @@ -29,7 +29,7 @@ Save yourself a few keystrokes. Follow the steps below:
    At this point, you can connect to your server without typing a password:

    ```bash
    ssh myserver.com
    ssh username@myserver.com
    ```

    2. If you would prefer to type `jupter` rather than `myserver.com`, run this
  9. @slowkow slowkow revised this gist Oct 12, 2014. 2 changed files with 62 additions and 53 deletions.
    62 changes: 62 additions & 0 deletions ssh-tutorial.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,62 @@
    # How to ssh to a remote server without typing your password

    Save yourself a few keystrokes. Follow the steps below:

    1. Run this Bash script on your laptop:

    ```bash
    #!/usr/bin/env bash

    # The hostname of your remote server.
    host=myserver.com

    # Create this folder if it does not exist: ~/.ssh
    mkdir ~/.ssh

    # Set the correct permissions (required)
    chmod 700 ~/.ssh

    # Generate an RSA key pair for identification with the remote server
    ssh-keygen -t rsa

    # Copy your public key to the remote server
    cat ~/.ssh/id_rsa.pub | ssh $host 'cat >> ~/.ssh/authorized_keys'

    # ssh is very strict about correct permissions
    ssh $host 'chmod g-w,o-w ~; chmod 700 ~/.ssh; chmod 600 ~/.ssh/authorized_keys'
    ```

    At this point, you can connect to your server without typing a password:

    ```bash
    ssh myserver.com
    ```

    2. If you would prefer to type `jupter` rather than `myserver.com`, run this
    Bash script on your laptop. You'll be able to use this alias with:
    `rsync`, `scp`, and `ssh`.
    ```bash
    #!/usr/bin/env bash
    cat >> ~/.ssh/config <<END
    Host jupiter
    User carl
    HostName myserver.com
    END
    ```
    3. If you want a single command to do two steps: (1) connect to a login server `jupiter`,
    and then connect to a work server `saturn`, configure your `~/.ssh/config` file as follows:
    ```
    # ~/.ssh/config
    Host jupiter
    User carl
    Hostname myserver.com
    Host saturn
    User carl
    ProxyCommand ssh -qX jupiter nc %h %p
    ```
    53 changes: 0 additions & 53 deletions ssh-tutorial.sh
    Original file line number Diff line number Diff line change
    @@ -1,53 +0,0 @@
    # How to ssh to a remote server without typing your password
    # ==========================================================

    host=myserver.com

    # Create this folder if it does not exist: ~/.ssh
    mkdir ~/.ssh

    # Set the correct permissions (required)
    chmod 700 ~/.ssh

    # Generate an RSA key pair for identification with the remote server
    ssh-keygen -t rsa

    # Copy your public key to the remote server
    cat ~/.ssh/id_rsa.pub | ssh $host 'cat >> ~/.ssh/authorized_keys'

    # ssh is very strict about correct permissions
    ssh $host 'chmod g-w,o-w ~; chmod 700 ~/.ssh; chmod 600 ~/.ssh/authorized_keys'

    # Now you can connect to the remote server without typing your password
    ssh $host

    # Create an alias for your server's address
    # (Use the alias with rsync, scp, ssh, etc.)
    alias=jupiter
    user=carl

    cat >> ~/.ssh/config <<END
    Host $alias
    User $username
    HostName $host
    END

    # Now these two commands are equivalent
    ssh myserver.com
    ssh jupiter

    # In one command:
    # ssh to a the login server and then the work server
    cat >> ~/.ssh/config <<END
    Host jupiter
    User carl
    Hostname myserver.com
    Host saturn
    User carl
    ProxyCommand ssh -qX jupiter nc %h %p
    # ProxyCommand ssh -q -W %h:%p jupiter
    END

    # Now you can connect directly to the work server from your laptop
    ssh saturn
  10. @slowkow slowkow revised this gist Aug 14, 2014. 1 changed file with 5 additions and 4 deletions.
    9 changes: 5 additions & 4 deletions ssh-tutorial.sh
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,8 @@
    # How to ssh to a remote server without typing your password
    # ==========================================================

    host=myserver.com

    # Create this folder if it does not exist: ~/.ssh
    mkdir ~/.ssh

    @@ -11,19 +13,18 @@ chmod 700 ~/.ssh
    ssh-keygen -t rsa

    # Copy your public key to the remote server
    cat ~/.ssh/id_rsa.pub | ssh myserver.com 'cat >> ~/.ssh/authorized_keys'
    cat ~/.ssh/id_rsa.pub | ssh $host 'cat >> ~/.ssh/authorized_keys'

    # ssh is very strict about correct permissions
    ssh myserver.com 'chmod g-w,o-w ~; chmod 700 ~/.ssh; chmod 600 ~/.ssh/authorized_keys'
    ssh $host 'chmod g-w,o-w ~; chmod 700 ~/.ssh; chmod 600 ~/.ssh/authorized_keys'

    # Now you can connect to the remote server without typing your password
    ssh myserver.com
    ssh $host

    # Create an alias for your server's address
    # (Use the alias with rsync, scp, ssh, etc.)
    alias=jupiter
    user=carl
    host=myserver.com

    cat >> ~/.ssh/config <<END
    Host $alias
  11. @slowkow slowkow revised this gist May 27, 2014. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion ssh-tutorial.sh
    Original file line number Diff line number Diff line change
    @@ -44,7 +44,8 @@ Host jupiter
    Host saturn
    User carl
    ProxyCommand ssh -q -W %h:%p jupiter
    ProxyCommand ssh -qX jupiter nc %h %p
    # ProxyCommand ssh -q -W %h:%p jupiter
    END

    # Now you can connect directly to the work server from your laptop
  12. @slowkow slowkow revised this gist May 24, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion ssh-tutorial.sh
    Original file line number Diff line number Diff line change
    @@ -36,7 +36,7 @@ ssh myserver.com
    ssh jupiter

    # In one command:
    # ssh to a login server and nc to a work server
    # ssh to a the login server and then the work server
    cat >> ~/.ssh/config <<END
    Host jupiter
    User carl
  13. @slowkow slowkow revised this gist May 24, 2014. 1 changed file with 15 additions and 15 deletions.
    30 changes: 15 additions & 15 deletions ssh-tutorial.sh
    Original file line number Diff line number Diff line change
    @@ -1,26 +1,26 @@
    # How to login to a remote server without typing your password
    # ============================================================
    # How to ssh to a remote server without typing your password
    # ==========================================================

    # Create this folder if it does not exist: ~/.ssh
    # Create this folder if it does not exist: ~/.ssh
    mkdir ~/.ssh

    # Set the correct permissions (required)
    # Set the correct permissions (required)
    chmod 700 ~/.ssh

    # Generate an RSA key pair for identification with the remote server
    # Generate an RSA key pair for identification with the remote server
    ssh-keygen -t rsa

    # Copy your public key to the remote server
    # Copy your public key to the remote server
    cat ~/.ssh/id_rsa.pub | ssh myserver.com 'cat >> ~/.ssh/authorized_keys'

    # ssh is very strict about correct permissions
    # ssh is very strict about correct permissions
    ssh myserver.com 'chmod g-w,o-w ~; chmod 700 ~/.ssh; chmod 600 ~/.ssh/authorized_keys'

    # Now you can connect to the remote server without typing your password
    # Now you can connect to the remote server without typing your password
    ssh myserver.com

    # Create an alias for your server's address
    # (Use the alias with rsync, scp, ssh, etc.)
    # Create an alias for your server's address
    # (Use the alias with rsync, scp, ssh, etc.)
    alias=jupiter
    user=carl
    host=myserver.com
    @@ -31,21 +31,21 @@ Host $alias
    HostName $host
    END

    # Now these two commands are equivalent
    # Now these two commands are equivalent
    ssh myserver.com
    ssh jupiter

    # In one command:
    # ssh to a login server and nc to a work server
    # In one command:
    # ssh to a login server and nc to a work server
    cat >> ~/.ssh/config <<END
    Host jupiter
    User carl
    Hostname myserver.com
    Host saturn
    User carl
    ProxyCommand ssh -qX jupiter nc %h %p
    ProxyCommand ssh -q -W %h:%p jupiter
    END

    # Now you can connect directly to the work server from your laptop
    # Now you can connect directly to the work server from your laptop
    ssh saturn
  14. @slowkow slowkow revised this gist Apr 3, 2014. 1 changed file with 0 additions and 8 deletions.
    8 changes: 0 additions & 8 deletions ssh-tutorial.sh
    Original file line number Diff line number Diff line change
    @@ -4,27 +4,21 @@
    # Create this folder if it does not exist: ~/.ssh
    mkdir ~/.ssh


    # Set the correct permissions (required)
    chmod 700 ~/.ssh


    # Generate an RSA key pair for identification with the remote server
    ssh-keygen -t rsa


    # Copy your public key to the remote server
    cat ~/.ssh/id_rsa.pub | ssh myserver.com 'cat >> ~/.ssh/authorized_keys'


    # ssh is very strict about correct permissions
    ssh myserver.com 'chmod g-w,o-w ~; chmod 700 ~/.ssh; chmod 600 ~/.ssh/authorized_keys'


    # Now you can connect to the remote server without typing your password
    ssh myserver.com


    # Create an alias for your server's address
    # (Use the alias with rsync, scp, ssh, etc.)
    alias=jupiter
    @@ -41,7 +35,6 @@ END
    ssh myserver.com
    ssh jupiter


    # In one command:
    # ssh to a login server and nc to a work server
    cat >> ~/.ssh/config <<END
    @@ -54,6 +47,5 @@ Host saturn
    ProxyCommand ssh -qX jupiter nc %h %p
    END


    # Now you can connect directly to the work server from your laptop
    ssh saturn
  15. @slowkow slowkow revised this gist Apr 3, 2014. 1 changed file with 0 additions and 11 deletions.
    11 changes: 0 additions & 11 deletions ssh-tutorial.sh
    Original file line number Diff line number Diff line change
    @@ -2,38 +2,31 @@
    # ============================================================

    # Create this folder if it does not exist: ~/.ssh

    mkdir ~/.ssh


    # Set the correct permissions (required)

    chmod 700 ~/.ssh


    # Generate an RSA key pair for identification with the remote server

    ssh-keygen -t rsa


    # Copy your public key to the remote server

    cat ~/.ssh/id_rsa.pub | ssh myserver.com 'cat >> ~/.ssh/authorized_keys'


    # ssh is very strict about correct permissions

    ssh myserver.com 'chmod g-w,o-w ~; chmod 700 ~/.ssh; chmod 600 ~/.ssh/authorized_keys'


    # Now you can connect to the remote server without typing your password

    ssh myserver.com


    # Create an alias for your server's address
    # (Use the alias with rsync, scp, ssh, etc.)

    alias=jupiter
    user=carl
    host=myserver.com
    @@ -45,15 +38,12 @@ Host $alias
    END

    # Now these two commands are equivalent

    ssh myserver.com

    ssh jupiter


    # In one command:
    # ssh to a login server and nc to a work server

    cat >> ~/.ssh/config <<END
    Host jupiter
    User carl
    @@ -66,5 +56,4 @@ END


    # Now you can connect directly to the work server from your laptop

    ssh saturn
  16. @slowkow slowkow revised this gist Mar 12, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion ssh-tutorial.sh
    Original file line number Diff line number Diff line change
    @@ -41,7 +41,7 @@ host=myserver.com
    cat >> ~/.ssh/config <<END
    Host $alias
    User $username
    HostName $domain
    HostName $host
    END

    # Now these two commands are equivalent
  17. @slowkow slowkow revised this gist Feb 5, 2014. 1 changed file with 0 additions and 2 deletions.
    2 changes: 0 additions & 2 deletions ssh-tutorial.sh
    Original file line number Diff line number Diff line change
    @@ -31,8 +31,6 @@ ssh myserver.com 'chmod g-w,o-w ~; chmod 700 ~/.ssh; chmod 600 ~/.ssh/authorized
    ssh myserver.com




    # Create an alias for your server's address
    # (Use the alias with rsync, scp, ssh, etc.)

  18. @slowkow slowkow revised this gist Feb 5, 2014. 1 changed file with 21 additions and 20 deletions.
    41 changes: 21 additions & 20 deletions ssh-tutorial.sh
    Original file line number Diff line number Diff line change
    @@ -36,7 +36,7 @@ ssh myserver.com
    # Create an alias for your server's address
    # (Use the alias with rsync, scp, ssh, etc.)

    alias=saturn
    alias=jupiter
    user=carl
    host=myserver.com

    @@ -50,22 +50,23 @@ END

    ssh myserver.com

    ssh saturn


    # Connect to a login server called login
    # and then connect a second time to a work server called work
    #
    # cat ~/.ssh/config
    #
    # Host login
    # User simon
    # Hostname myloginserver.com
    #
    # Host work
    # User simon
    # ProxyCommand ssh -qX login nc %h %p
    #
    # Now you can connect directly to work from your laptop
    #
    # ssh work
    ssh jupiter


    # In one command:
    # ssh to a login server and nc to a work server

    cat >> ~/.ssh/config <<END
    Host jupiter
    User carl
    Hostname myserver.com
    Host saturn
    User carl
    ProxyCommand ssh -qX jupiter nc %h %p
    END


    # Now you can connect directly to the work server from your laptop

    ssh saturn
  19. @slowkow slowkow revised this gist Feb 5, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion ssh-tutorial.sh
    Original file line number Diff line number Diff line change
    @@ -64,7 +64,7 @@ ssh saturn
    #
    # Host work
    # User simon
    # ProxyCommand ssh -qX A nc %h %p
    # ProxyCommand ssh -qX login nc %h %p
    #
    # Now you can connect directly to work from your laptop
    #
  20. @slowkow slowkow revised this gist Feb 4, 2014. 1 changed file with 7 additions and 0 deletions.
    7 changes: 7 additions & 0 deletions ssh-tutorial.sh
    Original file line number Diff line number Diff line change
    @@ -26,6 +26,13 @@ cat ~/.ssh/id_rsa.pub | ssh myserver.com 'cat >> ~/.ssh/authorized_keys'
    ssh myserver.com 'chmod g-w,o-w ~; chmod 700 ~/.ssh; chmod 600 ~/.ssh/authorized_keys'


    # Now you can connect to the remote server without typing your password

    ssh myserver.com




    # Create an alias for your server's address
    # (Use the alias with rsync, scp, ssh, etc.)

  21. @slowkow slowkow revised this gist Feb 4, 2014. 1 changed file with 6 additions and 0 deletions.
    6 changes: 6 additions & 0 deletions ssh-tutorial.sh
    Original file line number Diff line number Diff line change
    @@ -39,6 +39,12 @@ Host $alias
    HostName $domain
    END

    # Now these two commands are equivalent

    ssh myserver.com

    ssh saturn


    # Connect to a login server called login
    # and then connect a second time to a work server called work
  22. @slowkow slowkow revised this gist Feb 4, 2014. 1 changed file with 5 additions and 5 deletions.
    10 changes: 5 additions & 5 deletions ssh-tutorial.sh
    Original file line number Diff line number Diff line change
    @@ -6,27 +6,27 @@
    mkdir ~/.ssh


    # Set the correct permissions. (required)
    # Set the correct permissions (required)

    chmod 700 ~/.ssh


    # Generate an RSA key pair for identification with the remote server.
    # Generate an RSA key pair for identification with the remote server

    ssh-keygen -t rsa


    # Copy your public key to the remote server.
    # Copy your public key to the remote server

    cat ~/.ssh/id_rsa.pub | ssh myserver.com 'cat >> ~/.ssh/authorized_keys'


    # ssh is very strict about correct permissions.
    # ssh is very strict about correct permissions

    ssh myserver.com 'chmod g-w,o-w ~; chmod 700 ~/.ssh; chmod 600 ~/.ssh/authorized_keys'


    # Create an alias for your server's address.
    # Create an alias for your server's address
    # (Use the alias with rsync, scp, ssh, etc.)

    alias=saturn
  23. @slowkow slowkow revised this gist Feb 4, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion ssh-tutorial.sh
    Original file line number Diff line number Diff line change
    @@ -53,6 +53,6 @@ END
    # User simon
    # ProxyCommand ssh -qX A nc %h %p
    #
    # Now you can connect directly to B from your laptop
    # Now you can connect directly to work from your laptop
    #
    # ssh work
  24. @slowkow slowkow revised this gist Feb 4, 2014. 1 changed file with 12 additions and 12 deletions.
    24 changes: 12 additions & 12 deletions ssh-tutorial.sh
    Original file line number Diff line number Diff line change
    @@ -23,15 +23,15 @@ cat ~/.ssh/id_rsa.pub | ssh myserver.com 'cat >> ~/.ssh/authorized_keys'

    # ssh is very strict about correct permissions.

    ssh broad 'chmod g-w,o-w ~; chmod 700 ~/.ssh; chmod 600 ~/.ssh/authorized_keys'
    ssh myserver.com 'chmod g-w,o-w ~; chmod 700 ~/.ssh; chmod 600 ~/.ssh/authorized_keys'


    # Create an alias for your server's address.
    # (Use the alias with rsync, scp, ssh, ...)
    # (Use the alias with rsync, scp, ssh, etc.)

    alias=fry
    user=simon
    host=my.server.com
    alias=saturn
    user=carl
    host=myserver.com

    cat >> ~/.ssh/config <<END
    Host $alias
    @@ -40,19 +40,19 @@ Host $alias
    END


    # Connect to a login server A,
    # and then connect a second time to a work server B:
    # Connect to a login server called login
    # and then connect a second time to a work server called work
    #
    # cat ~/.ssh/config
    #
    # Host A
    # Host login
    # User simon
    # Hostname my.login-server.com
    # Hostname myloginserver.com
    #
    # Host B
    # Host work
    # User simon
    # ProxyCommand ssh -qX A nc %h %p
    #
    # Connect directly to B:
    # Now you can connect directly to B from your laptop
    #
    # ssh B
    # ssh work
  25. @slowkow slowkow created this gist Feb 4, 2014.
    58 changes: 58 additions & 0 deletions ssh-tutorial.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,58 @@
    # How to login to a remote server without typing your password
    # ============================================================

    # Create this folder if it does not exist: ~/.ssh

    mkdir ~/.ssh


    # Set the correct permissions. (required)

    chmod 700 ~/.ssh


    # Generate an RSA key pair for identification with the remote server.

    ssh-keygen -t rsa


    # Copy your public key to the remote server.

    cat ~/.ssh/id_rsa.pub | ssh myserver.com 'cat >> ~/.ssh/authorized_keys'


    # ssh is very strict about correct permissions.

    ssh broad 'chmod g-w,o-w ~; chmod 700 ~/.ssh; chmod 600 ~/.ssh/authorized_keys'


    # Create an alias for your server's address.
    # (Use the alias with rsync, scp, ssh, ...)

    alias=fry
    user=simon
    host=my.server.com

    cat >> ~/.ssh/config <<END
    Host $alias
    User $username
    HostName $domain
    END


    # Connect to a login server A,
    # and then connect a second time to a work server B:
    #
    # cat ~/.ssh/config
    #
    # Host A
    # User simon
    # Hostname my.login-server.com
    #
    # Host B
    # User simon
    # ProxyCommand ssh -qX A nc %h %p
    #
    # Connect directly to B:
    #
    # ssh B