

Copy the SSH key to your clipboard. If your SSH key file has a different name than the example code, modify the filename to match your current setup. When copying your key, don't add any newlines or whitespace. $ sudo apt-get install xclip # Downloads and installs xclip. If you don't have an existing public and private key pair, or don't wish to use any that are available to connect to GitHub, then generate a new SSH key. If you see an existing public and private key pair listed (for example idrsa.pub and idrsa ) that you would like to use to connect to GitHub, you can add your SSH key to the ssh-agent.
SSH keys come in pairs, a public key that gets shared with services like GitHub, and a private key that is stored only on your computer. If the keys match, you're granted access. The cryptography behind SSH keys ensures that no one can reverse engineer your private key from the public one. Generating an SSH key pair.
| importjava.io.{DataOutputStream, ByteArrayOutputStream, StringReader} |
| importjava.security.interfaces.{ECPublicKey, DSAParams, DSAPublicKey, RSAPublicKey} |
| importjava.security._ |
| importjava.security.spec.X509EncodedKeySpec |
| importorg.apache.commons.codec.binary.Base64 |
| importorg.bouncycastle.openssl.{PEMKeyPair, PEMParser} |
| objectgenPubSSHKey { |
| /** |
| * Generates a public key from a SSH private key. |
| * @paramprivateKey A RSA/DSA/EC private key |
| * @return SSH encoded public key |
| */ |
| defgetPublicKey(privateKey: String):String= { |
| valkp:PEMKeyPair=newPEMParser(newStringReader(privateKey)).readObject().asInstanceOf[PEMKeyPair] |
| valx509=newX509EncodedKeySpec(kp.getPublicKeyInfo.getEncoded) |
| valkeyFactory=if (privateKey.startsWith('-----BEGIN RSA PRIVATE KEY-----')) { |
| KeyFactory.getInstance('RSA') |
| } elseif (privateKey.startsWith('-----BEGIN DSA PRIVATE KEY-----')) { |
| KeyFactory.getInstance('DSA') |
| } elseif (privateKey.startsWith('-----BEGIN EC PRIVATE KEY-----')) { |
| KeyFactory.getInstance('EC') |
| } else { |
| thrownewException('Incompatible SSH key algorithm') |
| } |
| encodePublicKey(keyFactory.generatePublic(x509),'ozone') |
| } |
| privatedefencodePublicKey(publicKey: PublicKey, user: String):String= { |
| varpublicKeyEncoded:String=null |
| if (publicKey.getAlgorithm 'RSA') { |
| valrsaPublicKey:RSAPublicKey= publicKey.asInstanceOf[RSAPublicKey] |
| valbyteOs:ByteArrayOutputStream=newByteArrayOutputStream |
| valdos:DataOutputStream=newDataOutputStream(byteOs) |
| dos.writeInt('ssh-rsa'.getBytes.length) |
| dos.write('ssh-rsa'.getBytes) |
| dos.writeInt(rsaPublicKey.getPublicExponent.toByteArray.length) |
| dos.write(rsaPublicKey.getPublicExponent.toByteArray) |
| dos.writeInt(rsaPublicKey.getModulus.toByteArray.length) |
| dos.write(rsaPublicKey.getModulus.toByteArray) |
| publicKeyEncoded =newString(Base64.encodeBase64(byteOs.toByteArray)) |
| s'ssh-rsa $publicKeyEncoded user' |
| } |
| elseif (publicKey.getAlgorithm 'DSA') { |
| valdsaPublicKey:DSAPublicKey= publicKey.asInstanceOf[DSAPublicKey] |
| valdsaParams:DSAParams= dsaPublicKey.getParams |
| valbyteOs:ByteArrayOutputStream=newByteArrayOutputStream |
| valdos:DataOutputStream=newDataOutputStream(byteOs) |
| dos.writeInt('ssh-dss'.getBytes.length) |
| dos.write('ssh-dss'.getBytes) |
| dos.writeInt(dsaParams.getP.toByteArray.length) |
| dos.write(dsaParams.getP.toByteArray) |
| dos.writeInt(dsaParams.getQ.toByteArray.length) |
| dos.write(dsaParams.getQ.toByteArray) |
| dos.writeInt(dsaParams.getG.toByteArray.length) |
| dos.write(dsaParams.getG.toByteArray) |
| dos.writeInt(dsaPublicKey.getY.toByteArray.length) |
| dos.write(dsaPublicKey.getY.toByteArray) |
| publicKeyEncoded =newString(Base64.encodeBase64(byteOs.toByteArray)) |
| s'ssh-dss $publicKeyEncoded $user' |
| } elseif (publicKey.getAlgorithm 'EC') { |
| valecPublicKey:ECPublicKey= publicKey.asInstanceOf[ECPublicKey] |
| valbyteOs:ByteArrayOutputStream=newByteArrayOutputStream |
| valdos:DataOutputStream=newDataOutputStream(byteOs) |
| valcurveName= ecPublicKey.getParams.getCurve.getField.getFieldSize match { |
| case256=>'nistp256' |
| case384=>'nistp384' |
| case521=>'nistp521' |
| case _ =>thrownewException('Unknown curvesize') |
| } |
| valfullName=s'ecdsa-sha2-$curveName' |
| dos.writeInt(fullName.getBytes.length) |
| dos.write(fullName.getBytes) |
| dos.writeInt(curveName.getBytes.length) |
| dos.write(curveName.getBytes) |
| valgroup= ecPublicKey.getW |
| valelementSize:Int= (ecPublicKey.getParams.getCurve.getField.getFieldSize +7) /8 |
| valM:Array[Byte] =newArray[Byte](2* elementSize +1) |
| M(0) =0x04.toByte |
| valaffineX:Array[Byte] = group.getAffineX.toByteArray.dropWhile(_ 0x00) |
| Array.copy(affineX, 0, M, 1+ elementSize - affineX.length, affineX.length) |
| valaffineY:Array[Byte] = group.getAffineY.toByteArray.dropWhile(_ 0x00) |
| Array.copy(affineY, 0, M, 1+ elementSize + elementSize - affineY.length, affineY.length) |
| dos.writeInt(M.length) |
| dos.write(M) |
| publicKeyEncoded =newString(Base64.encodeBase64(byteOs.toByteArray)) |
| s'$fullName $publicKeyEncoded $user' |
| } |
| else { |
| thrownewIllegalArgumentException('Unknown public key encoding: '+ publicKey.getAlgorithm) |
| } |
| } |
| } |
Nov 23, 2015 Using SSH public-key authentication to connect to a remote system - svlada/ssh-public-key-authentication. Using SSH public-key authentication to connect to a remote system - svlada/ssh-public-key-authentication. GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together. Generating a new SSH key. Open Terminal Terminal Git Bash the terminal. Paste the text below, substituting in your GitHub Enterprise email address. $ ssh-keygen -t rsa -b 4096 -C 'youremail@example.com' This creates a new ssh key, using the provided email as a label. Generating public/private rsa key pair. How To Add SSH Key To Github Account Log into your Github's account. In the top right corner of any page, click your profile photo, then click Settings. In the user settings sidebar, go to SSH and GPG keys. Generating Your SSH Public Key Many Git servers authenticate using SSH public keys. In order to provide a public key, each user in your system must generate one if they don’t already have one. This process is similar across all operating systems.