-
-
Save AliAryanTech/a54621e44df2062f4d99a31b8064d121 to your computer and use it in GitHub Desktop.
ssh to a server without typing your password
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # How to ssh 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 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 | |
| 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 -q -W %h:%p jupiter | |
| END | |
| # Now you can connect directly to the work server from your laptop | |
| ssh saturn |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment