Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # 1. Automatic authentication to remote machine
- ````
- Note:- with this you don't need to type password every time to do the ssh connection.
- ````
- ### Step One—Create the RSA Key Pair (your machine)
- ````
- ssh-keygen -t rsa
- ````
- ### Step Two—Store the Keys and Passphrase (your machine)
- Once you have entered the Gen Key command, you will get a few more questions:
- ````
- Enter file in which to save the key (/home/demo/.ssh/id_rsa):
- ````
- You can press enter here, saving the file to the user home (in this case, my example user is called demo).
- ````
- Enter passphrase (empty for no passphrase):
- ````
- The entire key generation process looks like this:
- ````
- ssh-keygen -t rsa
- ````
- ````
- Generating public/private rsa key pair.
- Enter file in which to save the key (/home/demo/.ssh/id_rsa):
- Enter passphrase (empty for no passphrase):
- Enter same passphrase again:
- Your identification has been saved in /home/demo/.ssh/id_rsa.
- Your public key has been saved in /home/demo/.ssh/id_rsa.pub.
- The key fingerprint is:
- 4a:dd:0a:c6:35:4e:3f:ed:27:38:8c:74:44:4d:93:67 demo@a
- The key's randomart image is:
- +--[ RSA 2048]----+
- | .oo. |
- | . o.E |
- | + . o |
- | . = = . |
- | = S = . |
- | o + = + |
- | . o + o . |
- | . o |
- | |
- +-----------------+
- ````
- ``The public key is now located in /home/demo/.ssh/id_rsa.pub. The private key (identification) is now located in /home/demo/.ssh/id_rsa.``
- ### Step Three—Copy the Public Key (your machine to remote_machine)
- Once the key pair is generated, it’s time to place the public key on the server that we want to use.
- You can copy the public key into the new machine’s authorized_keys file with the ssh-copy-id command. Make sure to replace the example username and IP address below.
- ````
- ssh-copy-id demo@198.51.100.0
- ````
- # 2. Custom host name for ssh connection
- ````
- Note:- instead of typing ``ssh user@remote.machine.ip`` you can use ``ssh host_name`` to connect easily.
- ````
- First we need to modify the config file in our machine to automatically resolve the ip address of the ``host_name`` when we will ssh into it.
- ````
- vim ~/.ssh/config
- ````
- The general format looks like this
- ````
- Host firsthost
- SSH_OPTION_1 custom_value
- SSH_OPTION_2 custom_value
- SSH_OPTION_3 custom_value
- Host secondhost
- ANOTHER_OPTION custom_value
- Host *host
- ANOTHER_OPTION custom_value
- Host *
- CHANGE_DEFAULT custom_value
- ````
- To add a new host name consider this example:
- ````
- Host my_remote_machine
- HostName 192.168.0.142
- User neo
- ````
- This host allows us to connect as neo@192.168.0.142 by typing this on the command line:
- ````
- ssh my_remote_machine
- ````
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement