Advertisement
Guest User

Untitled

a guest
Oct 15th, 2019
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.63 KB | None | 0 0
  1. # 1. Automatic authentication to remote machine
  2. ````
  3. Note:- with this you don't need to type password every time to do the ssh connection.
  4. ````
  5.  
  6. ### Step One—Create the RSA Key Pair (your machine)
  7. ````
  8. ssh-keygen -t rsa
  9. ````
  10. ### Step Two—Store the Keys and Passphrase (your machine)
  11. Once you have entered the Gen Key command, you will get a few more questions:
  12. ````
  13. Enter file in which to save the key (/home/demo/.ssh/id_rsa):
  14. ````
  15. You can press enter here, saving the file to the user home (in this case, my example user is called demo).
  16. ````
  17. Enter passphrase (empty for no passphrase):
  18. ````
  19. The entire key generation process looks like this:
  20. ````
  21. ssh-keygen -t rsa
  22. ````
  23. ````
  24. Generating public/private rsa key pair.
  25. Enter file in which to save the key (/home/demo/.ssh/id_rsa):
  26. Enter passphrase (empty for no passphrase):
  27. Enter same passphrase again:
  28. Your identification has been saved in /home/demo/.ssh/id_rsa.
  29. Your public key has been saved in /home/demo/.ssh/id_rsa.pub.
  30. The key fingerprint is:
  31. 4a:dd:0a:c6:35:4e:3f:ed:27:38:8c:74:44:4d:93:67 demo@a
  32. The key's randomart image is:
  33. +--[ RSA 2048]----+
  34. | .oo. |
  35. | . o.E |
  36. | + . o |
  37. | . = = . |
  38. | = S = . |
  39. | o + = + |
  40. | . o + o . |
  41. | . o |
  42. | |
  43. +-----------------+
  44. ````
  45.  
  46. ``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.``
  47.  
  48. ### Step Three—Copy the Public Key (your machine to remote_machine)
  49. Once the key pair is generated, it’s time to place the public key on the server that we want to use.
  50.  
  51. 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.
  52. ````
  53. ssh-copy-id demo@198.51.100.0
  54. ````
  55.  
  56. # 2. Custom host name for ssh connection
  57. ````
  58. Note:- instead of typing ``ssh user@remote.machine.ip`` you can use ``ssh host_name`` to connect easily.
  59. ````
  60. 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.
  61. ````
  62. vim ~/.ssh/config
  63. ````
  64. The general format looks like this
  65. ````
  66. Host firsthost
  67. SSH_OPTION_1 custom_value
  68. SSH_OPTION_2 custom_value
  69. SSH_OPTION_3 custom_value
  70.  
  71. Host secondhost
  72. ANOTHER_OPTION custom_value
  73.  
  74. Host *host
  75. ANOTHER_OPTION custom_value
  76.  
  77. Host *
  78. CHANGE_DEFAULT custom_value
  79. ````
  80. To add a new host name consider this example:
  81. ````
  82. Host my_remote_machine
  83. HostName 192.168.0.142
  84. User neo
  85. ````
  86. This host allows us to connect as neo@192.168.0.142 by typing this on the command line:
  87. ````
  88. ssh my_remote_machine
  89. ````
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement