Guest User

Untitled

a guest
Jan 24th, 2018
318
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.48 KB | None | 0 0
  1. ssh-keygen
  2.  
  3. ssh-copy-id user@host
  4. ## or if your server uses custom port no:
  5. ssh-copy-id "user@host -p 1234"
  6.  
  7. ssh user@host
  8.  
  9. not-marco@rinzwind-desktop:~$ ssh-keygen
  10. Generating public/private rsa key pair.
  11. Enter file in which to save the key (/home/not-marco/.ssh/id_rsa):
  12. Created directory '/home/not-marco/.ssh'.
  13. Enter passphrase (empty for no passphrase):
  14. Enter same passphrase again:
  15. Your identification has been saved in /home/not-marco/.ssh/id_rsa.
  16. Your public key has been saved in /home/not-marco/.ssh/id_rsa.pub.
  17. The key fingerprint is:
  18. b1:25:04:21:1a:38:73:38:3c:e9:e4:5b:81:e9:ac:0f not-marco@rinzwind-desktop
  19. The key's randomart image is:
  20. +--[ RSA 2048]----+
  21. |.o= . oo. |
  22. |*B.+ . . |
  23. |*=o . o . |
  24. | = . = |
  25. |. o S |
  26. |E. |
  27. | o |
  28. | . |
  29. | |
  30. +-----------------+
  31. not-marco@rinzwind-desktop:~$ ssh-copy-id not-marco@127.0.0.1
  32. not-marco@127.0.0.1's password:
  33. Now try logging into the machine, with "ssh 'not-marco@127.0.0.1'", and check in:
  34.  
  35. ~/.ssh/authorized_keys
  36.  
  37. to make sure we haven't added extra keys that you weren't expecting.
  38.  
  39. sshpass -p 'password' ssh your_username@your_server
  40.  
  41. #PasswordAuthentication yes
  42.  
  43. PasswordAuthentication no
  44.  
  45. $ sudo chmod 700 .ssh && chmod 600 .ssh/authorized_keys
  46.  
  47. ssh-keygen -b 4096
  48.  
  49. Protocol 1,2
  50.  
  51. remote=user@remotehost # fill in correct user and remotehost names
  52. cd $HOME/.ssh
  53. # create .ssh on remote host if it is non-existing:
  54. ssh $remote 'if [ ! -d .ssh ]; then mkdir .ssh; fi'
  55. # copy RSA1 key:
  56. scp identity.pub ${remote}:.ssh
  57. ssh $remote "cd .ssh; cat identity.pub >> authorized_keys"
  58.  
  59. remote=user@remotehost # fill in correct user and remotehost names
  60. cd $HOME/.ssh
  61. # create .ssh on remote host if it is non-existing:
  62. ssh $remote 'if [ ! -d .ssh ]; then mkdir .ssh; fi'
  63. # copy DSA key:
  64. scp id_dsa.pub ${remote}:.ssh
  65. ssh $remote "cd .ssh; cat id_dsa.pub >> authorized_keys2"
  66.  
  67. #!/bin/sh
  68.  
  69. # create ssh connections without giving a password
  70.  
  71. if [ $# -lt 1 ]; then
  72. echo Usage: $0 username@remotehost
  73. exit
  74. fi
  75. remote="$1" # 1st command-line argument is the user@remotehost address
  76. this=$HOST # name of client host
  77.  
  78. # first check if we need to run ssh-keygen for generating
  79. # $HOME/.ssh with public and private keys:
  80. if [ ! -d $HOME/.ssh ]; then
  81. echo "just type RETURN for each question:" # no passphrase - unsecure!!
  82. # generate RSA1, RSA and DSA keys:
  83. echo; echo; echo
  84. ssh-keygen
  85. echo; echo; echo
  86. ssh-keygen -t rsa
  87. echo; echo; echo
  88. ssh-keygen -t dsa
  89. else
  90. # we have $HOME/.ssh, but check that we have all types of
  91. # keys (RSA1, RSA, DSA):
  92. if [ ! -f $HOME/.ssh/identity ]; then
  93. # generate RSA1 keys:
  94. echo "just type RETURN for each question:" # no passphrase - unsecure!!
  95. ssh-keygen
  96. fi
  97. if [ ! -f $HOME/.ssh/id_rsa ]; then
  98. # generate RSA keys:
  99. echo "just type RETURN for each question:" # no passphrase - unsecure!!
  100. ssh-keygen -t rsa
  101. fi
  102. if [ ! -f $HOME/.ssh/id_rsa ]; then
  103. # generate DSA keys:
  104. echo "just type RETURN for each question:" # no passphrase - unsecure!!
  105. ssh-keygen -t dsa
  106. fi
  107. fi
  108.  
  109.  
  110. cd $HOME/.ssh
  111.  
  112. if [ ! -f config ]; then
  113. # make ssh try ssh -1 (RSA1 keys) first and then ssh -2 (DSA keys)
  114. echo "Protocol 1,2" > config
  115. fi
  116.  
  117. # copy public keys (all three types) to the destination host:
  118.  
  119. echo; echo; echo
  120. # create .ssh on remote host if it's not there:
  121. ssh $remote 'if [ ! -d .ssh ]; then mkdir .ssh; fi'
  122. # copy RSA1 key:
  123. scp identity.pub ${remote}:.ssh/${this}_rsa1.pub
  124. # copy RSA key:
  125. #scp id_rsa.pub ${remote}:.ssh/${this}_rsa.pub
  126. # copy DSA key:
  127. scp id_dsa.pub ${remote}:.ssh/${this}_dsa.pub
  128. # make authorized_keys(2) files on remote host:
  129.  
  130. echo; echo; echo
  131. # this one copies all three keys:
  132. #ssh $remote "cd .ssh; touch authorized_keys authorized_keys2; cat ${this}_rsa1.pub >> authorized_keys; cat ${this}_rsa.pub >> authorized_keys2; cat ${this}_dsa.pub >> authorized_keys2;"
  133. # this one copies RSA1 and DSA keys:
  134. ssh $remote "cd .ssh; touch authorized_keys authorized_keys2; cat ${this}_rsa1.pub >> authorized_keys; cat ${this}_dsa.pub >> authorized_keys2;"
  135.  
  136. echo; echo; echo
  137. echo "try an ssh $remote"
  138.  
  139. curl https://raw.github.com/beautifulcode/ssh-copy-id-for-OSX/master/ssh-copy-id.sh -o /usr/local/bin/ssh-copy-id
  140. chmod +x /usr/local/bin/ssh-copy-id
  141.  
  142. ssh-copy-id "not-marco@127.0.0.1 -p 2222"
  143.  
  144. ssh-keygen
  145. ssh-copy-id -i ~/.ssh/12gpu_server.pub lerner@192.168.20.160
  146.  
  147. Host *
  148. IdentitiesOnly yes
  149.  
  150. Host 12gpu
  151. HostName 192.168.20.160
  152. User lerner
  153. IdentityFile ~/.ssh/12gpu_server
Add Comment
Please, Sign In to add comment