SSH秘钥生成

来源:互联网 发布:java webp格式转换jpg 编辑:程序博客网 时间:2024/06/05 07:44

如果没有代码权限,clone代码的时候会提示

kabdamatoAir:未命名文件夹 lcy$ git clone git@bitbucket.org:xialiuliu/swift.gitCloning into 'swift'...Warning: Permanently added the RSA host key for IP address '104.192.143.2' to the list of known hosts.Permission denied (publickey).fatal: Could not read from remote repository.Please make sure you have the correct access rightsand the repository exists.

如果代码权限为输入密码而不是秘钥,则可以向代码权限管理的人要密码,输入相应密码下载即可

kabdamatoAir:未命名文件夹 lcy$ git clone https://xialiuliu@bitbucket.org/xialiuliu/swift.gitCloning into 'swift'...Password for 'https://xialiuliu@bitbucket.org': remote: Counting objects: 144, done.remote: Compressing objects: 100% (125/125), done.remote: Total 144 (delta 49), reused 0 (delta 0)Receiving objects: 100% (144/144), 54.91 KiB | 0 bytes/s, done.Resolving deltas: 100% (49/49), done.Checking connectivity... done.

正常情况都是要提供秘钥的,进入本机的ssh文件夹,里面有一对默认的公钥和私钥,id_rsa和id_rsa.pub,cat id_rsa.pub文件,将text发送给代码管理人员添加公钥权限,就可正常clone代码了

如果已经有ssh key ,copy 你的key with

cat ~/.ssh/id_rsa.pub | pbcopy

更多操作:

kabdamatoAir:未命名文件夹 lcy$ cdkabdamatoAir:~ lcy$ pwd/Users/lcykabdamatoAir:~ lcy$ ls -altotal 160drwxr-xr-x+ 43 lcy   staff   1462 12 26 12:11 .drwxr-xr-x   6 root  admin    204 11  2 11:09 ..-r--------   1 lcy   staff      9  4  7  2015 .CFUserTextEncoding-rw-r--r--@  1 lcy   staff  12292  1  4 09:39 .DS_Storedrwxr-xr-x   3 lcy   staff    102  3  5  2015 .ShadowsocksXdrwx------  13 lcy   staff    442  1  6 10:20 .Trash-rw-------   1 lcy   staff  11423  1  6 15:24 .bash_history-rw-r--r--   1 lcy   staff    200  9 24  2014 .bash_profile-rw-r--r--   1 lcy   staff     68  9 24  2014 .bashrcdrwxr-xr-x   3 lcy   staff    102  6 16  2014 .cocoapodsdrwxr-xr-x   5 lcy   staff    170  3 24  2015 .configdrwxr-xr-x   3 lcy   staff    102 10 30  2014 .configpropsdrwxr-xr-x   3 lcy   staff    102 10 30  2014 .datastoragedrwxr-xr-x   3 lcy   staff    102  6 16  2014 .gem-rw-r--r--   1 lcy   staff    117  6 16  2014 .gemrc-rw-r--r--   1 lcy   staff    654  8  7 16:09 .gitconfig-rw-r--r--@  1 lcy   staff     30 10  9  2014 .gitignore_global-rw-r--r--@  1 lcy   staff     43 10  9  2014 .hgignore_globaldrwxr-xr-x  14 lcy   staff    476 12 14 10:23 .itmstransporterdrwxr-xr-x   3 lcy   staff    102  4  8  2015 .keepassxdrwxr-xr-x   3 lcy   staff    102  3 24  2015 .localdrwxr-xr-x   3 lcy   staff    102 12 26 12:11 .oracle_jre_usage-rw-r--r--   1 lcy   staff     68  9 24  2014 .profiledrwx------   3 lcy   staff    102  8 13  2014 .putty-rw-------   1 lcy   staff   1024  5 22  2015 .rnddrwxr-xr-x  30 lcy   staff   1020  9 24  2014 .rvmdrwx------   8 lcy   staff    272  4 29  2015 .sshdrwxr-xr-x   6 lcy   staff    204  9 11  2014 .subversion-rw-------   1 lcy   staff   7134 12 14 10:45 .viminfo-rw-r--r--   1 lcy   staff    118  9 24  2014 .zlogin-rw-r--r--   1 lcy   staff     68  9 24  2014 .zshrcdrwx------   4 lcy   staff    136  8  7 10:10 Applicationsdrwx------+ 31 lcy   staff   1054  1  6 15:23 Desktopdrwx------+  4 lcy   staff    136  3 18  2015 Documentsdrwx------+ 35 lcy   staff   1190  1  6 14:38 Downloadsdrwx------@ 64 lcy   staff   2176 11 30 14:33 Librarydrwx------+  3 lcy   staff    102  6  6  2014 Moviesdrwx------+  4 lcy   staff    136  6 26  2014 Musicdrwx------+ 14 lcy   staff    476 11  2 11:02 Picturesdrwxr-xr-x+  5 lcy   staff    170  6  6  2014 Publicdrwxr-xr-x   3 lcy   staff    102  6 23  2014 Sitesdrwxr-xr-x@ 17 lcy   staff    578  1  4 11:53 Syncdrwxr-xr-x   8 lcy   staff    272 10 29 17:34 swiftkabdamatoAir:~ lcy$ ls -l\total 0drwx------   4 lcy  staff   136  8  7 10:10 Applicationsdrwx------+ 31 lcy  staff  1054  1  6 15:23 Desktopdrwx------+  4 lcy  staff   136  3 18  2015 Documentsdrwx------+ 35 lcy  staff  1190  1  6 14:38 Downloadsdrwx------@ 64 lcy  staff  2176 11 30 14:33 Librarydrwx------+  3 lcy  staff   102  6  6  2014 Moviesdrwx------+  4 lcy  staff   136  6 26  2014 Musicdrwx------+ 14 lcy  staff   476 11  2 11:02 Picturesdrwxr-xr-x+  5 lcy  staff   170  6  6  2014 Publicdrwxr-xr-x   3 lcy  staff   102  6 23  2014 Sitesdrwxr-xr-x@ 17 lcy  staff   578  1  4 11:53 Syncdrwxr-xr-x   8 lcy  staff   272 10 29 17:34 swiftkabdamatoAir:~ lcy$ cd .sshkabdamatoAir:.ssh lcy$ pwd/Users/lcy/.sshkabdamatoAir:.ssh lcy$ ls -altotal 56drwx------   8 lcy  staff   272  4 29  2015 .drwxr-xr-x+ 43 lcy  staff  1462 12 26 12:11 ..-rw-r--r--@  1 lcy  staff  6148  4 29  2015 .DS_Store-rw-------@  1 lcy  staff  1766  4 29  2015 github_rsa-rw-r--r--@  1 lcy  staff   402  4 29  2015 github_rsa.pub-rw-------@  1 lcy  staff  1679  4 29  2015 id_rsa-rw-r--r--@  1 lcy  staff   399  4 29  2015 id_rsa.pub-rw-r--r--@  1 lcy  staff  3611  1  6 15:27 known_hostskabdamatoAir:.ssh lcy$ cp id_rsa id_rsa.backkabdamatoAir:.ssh lcy$ cp id_rsa.pub id_rsa.pub.backkabdamatoAir:.ssh lcy$ ls -altotal 72drwx------  10 lcy  staff   340  1  6 15:33 .drwxr-xr-x+ 43 lcy  staff  1462 12 26 12:11 ..-rw-r--r--@  1 lcy  staff  6148  4 29  2015 .DS_Store-rw-------@  1 lcy  staff  1766  4 29  2015 github_rsa-rw-r--r--@  1 lcy  staff   402  4 29  2015 github_rsa.pub-rw-------@  1 lcy  staff  1679  4 29  2015 id_rsa-rw-------@  1 lcy  staff  1679  1  6 15:33 id_rsa.back-rw-r--r--@  1 lcy  staff   399  4 29  2015 id_rsa.pub-rw-r--r--@  1 lcy  staff   399  1  6 15:33 id_rsa.pub.back-rw-r--r--@  1 lcy  staff  3611  1  6 15:27 known_hostskabdamatoAir:.ssh lcy$ gengen_bridge_metadata  gencat               genstringskabdamatoAir:.ssh lcy$ gengen_bridge_metadata  gencat               genstringskabdamatoAir:.ssh lcy$ sshssh          ssh-add      ssh-agent    ssh-keygen   ssh-keyscan  sshdkabdamatoAir:.ssh lcy$ sshssh          ssh-add      ssh-agent    ssh-keygen   ssh-keyscan  sshdkabdamatoAir:.ssh lcy$ ssh-keyssh-keygen   ssh-keyscan  kabdamatoAir:.ssh lcy$ ssh-keygen --helpssh-keygen: illegal option -- -usage: ssh-keygen [options]Options:  -A          Generate non-existent host keys for all key types.  -a trials   Number of trials for screening DH-GEX moduli.  -B          Show bubblebabble digest of key file.  -b bits     Number of bits in the key to create.  -C comment  Provide new comment.  -c          Change comment in private and public key files.  -D pkcs11   Download public key from pkcs11 token.  -e          Export OpenSSH to foreign format key file.  -F hostname Find hostname in known hosts file.  -f filename Filename of the key file.  -G file     Generate candidates for DH-GEX moduli.  -g          Use generic DNS resource record format.  -H          Hash names in known_hosts file.  -h          Generate host certificate instead of a user certificate.  -I key_id   Key identifier to include in certificate.  -i          Import foreign format to OpenSSH key file.  -J number   Screen this number of moduli lines.  -j number   Start screening moduli at specified line.  -K checkpt  Write checkpoints to this file.  -k          Generate a KRL file.  -L          Print the contents of a certificate.  -l          Show fingerprint of key file.  -M memory   Amount of memory (MB) to use for generating DH-GEX moduli.  -m key_fmt  Conversion format for -e/-i (PEM|PKCS8|RFC4716).  -N phrase   Provide new passphrase.  -n name,... User/host principal names to include in certificate  -O option   Specify a certificate option.  -P phrase   Provide old passphrase.  -p          Change passphrase of private key file.  -Q          Test whether key(s) are revoked in KRL.  -q          Quiet.  -R hostname Remove host from known_hosts file.  -r hostname Print DNS resource record.  -S start    Start point (hex) for generating DH-GEX moduli.  -s ca_key   Certify keys with CA key.  -T file     Screen candidates for DH-GEX moduli.  -t type     Specify type of key to create.  -u          Update KRL rather than creating a new one.  -V from:to  Specify certificate validity interval.  -v          Verbose.  -W gen      Generator to use for generating DH-GEX moduli.  -y          Read private key file and print public key.  -z serial   Specify a serial number.

生成一对名为”test”的公钥秘钥

    kabdamatoAir:.ssh lcy$ ssh-keygen -f test     Generating public/private rsa key pair.    Enter passphrase (empty for no passphrase):     Enter same passphrase again:     Your identification has been saved in test.    Your public key has been saved in test.pub.    The key fingerprint is:    0d:46:8f:1a:d0:a7:bd:0e:4d:94:eb:6d:7c:ac:20:d6 lcy@kabdamatoAir.lan    The key's randomart image is:    +--[ RSA 2048]----+    |    ..  ..       |    |     ...+o       |    |      .=+..      |    |      .++o       |    |      .=S+..     |    |      + E + o    |    |     . + o o     |    |        . .      |    |                 |    +-----------------+    kabdamatoAir:.ssh lcy$ ls -al    total 88    drwx------  12 lcy  staff   408  1  6 15:36 .    drwxr-xr-x+ 43 lcy  staff  1462 12 26 12:11 ..    -rw-r--r--@  1 lcy  staff  6148  4 29  2015 .DS_Store    -rw-------@  1 lcy  staff  1766  4 29  2015 github_rsa    -rw-r--r--@  1 lcy  staff   402  4 29  2015 github_rsa.pub    -rw-------@  1 lcy  staff  1679  4 29  2015 id_rsa    -rw-------@  1 lcy  staff  1679  1  6 15:33 id_rsa.back    -rw-r--r--@  1 lcy  staff   399  4 29  2015 id_rsa.pub    -rw-r--r--@  1 lcy  staff   399  1  6 15:33 id_rsa.pub.back    -rw-r--r--@  1 lcy  staff  3611  1  6 15:27 known_hosts(系统生成文件,存键值)    -rw-------   1 lcy  staff  1679  1  6 15:36 test    -rw-r--r--   1 lcy  staff   402  1  6 15:36 test.pub

打开test.pub

kabdamatoAir:.ssh lcy$ cat test.pub ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCp2RSOd1qIm49lt3zwS/PJ1zakK3ZfRuCYxvJB9PTWmA4qZVBV8zzV1+AQSMx3IL7saZ+QVeV/cxfGPO2t5CHfMIGBJLdEwmG9SfSLkHlrF66UfrEPefBA7Mahb03HL33g11Nu9A0HUs0cbFILmTQLmFx84IFoYeuy48YSZjZUWyDnyHbzqS+qCzAhs4AA4uJANSbo+gNkM7w4LA72Sc1Uj15vGRBr4nj/A5wsq2bQ8xAUEOI0jfQF0wPcI0TdJ5/Hj+ZsmD9VWHgY+nXAGYn/vrrUGNTkrTsqXsK0HUa55FVfWyjrdXWaTYVye9dMVGYO1CfgRwBYZNH92nrhIxcH lcy@kabdamatoAir.lan

//如果秘钥由一台设备拷贝到另一台,下载代码报错查看一下是不是秘钥的权限不对了
chomd修改秘钥权限
-rw-r–r—
第一位d代表是否为文件夹
后面每三位代表一组如图分别为
是否文件夹 个人权限 组成员权限 其他人权限
- rw- r— -r-
420=6 4 = 4 2=2
不是文件夹 可读可写不可执行结果为6 只可读最后为4 最后为2

    kabdamatoAir:.ssh lcy$ chmod 660 test    kabdamatoAir:.ssh lcy$ ls -al    total 88    drwx------  12 lcy  staff   408  1  6 15:36 .    drwxr-xr-x+ 43 lcy  staff  1462 12 26 12:11 ..    -rw-r--r--@  1 lcy  staff  6148  4 29  2015 .DS_Store    -rw-------@  1 lcy  staff  1766  4 29  2015 github_rsa    -rw-r--r--@  1 lcy  staff   402  4 29  2015 github_rsa.pub    -rw-------@  1 lcy  staff  1679  4 29  2015 id_rsa    -rw-------@  1 lcy  staff  1679  1  6 15:33 id_rsa.back    -rw-r--r--@  1 lcy  staff   399  4 29  2015 id_rsa.pub    -rw-r--r--@  1 lcy  staff   399  1  6 15:33 id_rsa.pub.back    -rw-r--r--@  1 lcy  staff  3611  1  6 15:27 known_hosts    -rw-rw----   1 lcy  staff  1679  1  6 15:36 test    -rw-r--r--   1 lcy  staff   402  1  6 15:36 test.pub    kabdamatoAir:.ssh lcy$ chmod 600 test    kabdamatoAir:.ssh lcy$ ls -al    total 88    drwx------  12 lcy  staff   408  1  6 15:36 .    drwxr-xr-x+ 43 lcy  staff  1462 12 26 12:11 ..    -rw-r--r--@  1 lcy  staff  6148  4 29  2015 .DS_Store    -rw-------@  1 lcy  staff  1766  4 29  2015 github_rsa    -rw-r--r--@  1 lcy  staff   402  4 29  2015 github_rsa.pub    -rw-------@  1 lcy  staff  1679  4 29  2015 id_rsa    -rw-------@  1 lcy  staff  1679  1  6 15:33 id_rsa.back    -rw-r--r--@  1 lcy  staff   399  4 29  2015 id_rsa.pub    -rw-r--r--@  1 lcy  staff   399  1  6 15:33 id_rsa.pub.back    -rw-r--r--@  1 lcy  staff  3611  1  6 15:27 known_hosts    -rw-------   1 lcy  staff  1679  1  6 15:36 test    -rw-r--r--   1 lcy  staff   402  1  6 15:36 test.pub    kabdamatoAir:.ssh lcy$ cat test    -----BEGIN RSA PRIVATE KEY-----    MIIEpAIBAAKCAQEAqdkUjndaiJuPZbd88Evzydc2pCt2X0bgmMbyQfT01pgOKmVQ    VfM81dfgEEjMdyC+7GmfkFXlf3MXxjztreQh3zCBgSS3RMJhvUn0i5B5axeulH6x    D3nwQOzGoW9Nxy994NdTbvQNB1LNHGxSC5k0C5hcfOCBaGHrsuPGEmY2VFsg58h2    86kvqgswIbOAAOLiQDUm6PoDZDO8OCwO9knNVI9ebxkQa+J4/wOcLKtm0PMQFBDi    NI30BdMD3CNE3Sefx4/mbJg/VVh4GPp1wBmJ/7661BjU5K07Kl7CtB1GueRVX1so    63V1mk2FcnvXTFRmDtQn4EcAWGTR/dp64SMXBwIDAQABAoIBAGraZPJT6CL1Krul    Ofa68b5TpM6XgTrjjjzPPG1+O+Idexv07RuFkQo/a3kTM37mnPaCZJ4bS+xobdaL    UkQJt71/+JlUje+2EmNReYWr+JcFKRHGuoGwBxPxYe0B5v6exCSFkrnE08V9tAhj    pSIi2flJezYcz4zpvaynW18L6rYaL6/FNtloxVq2vCZ4mBTphzpfZi82qrLF8kZM    6RdWuZjahuLmijNmlZu5BxdGtqwC+igBsdhfLJuVkDOOUf549FElgcQGbX8gWwx3    1cC3HIPjtuMc7u3/89Najp6GH30f69sGWVIeZeUq51GO8vCzGvAmCho9nRlPJ73n    kZYz24ECgYEA3g/1k+dOPh076Ur50K2d+gqFBWjMOGPPGo/GhMv4hWpootgHTqCb    8BmvHF4+Lnnlv7oBT9ygEL65tz7rbxDhVxxi/HY2vHnkuTDP52HN3AghMzfUIv1l    d/F5eMlKtC1ajo0NxwWCM7PSRVvlh9HWHIs8Kb3pSlZh4/aoQ58kvWECgYEAw85E    xRRUfmmHeDsMAFT14IxgCvU9SpbJA2MVaMJKt+RDqy1IY9a4XZeDmKDacB4qq1iI    yTszI0BUcr5IzRaBGowLVGBbKyA2WW7imqJRHG7Nof5sJajZTeZjHAm22ubYuaCn    POoDQHzCxpxwzfjMRn0XzHW+RCC1H6T5EhqoBWcCgYEAlf37p9KGFAiVDih5gw2y    dlEitpupzbEFE/Dna42GqT9NvCjlDqQHkG8Yy7WQlL37hLxz5GimqYjaUr8qMZQa    UUe4SMTkhfxjlP82fxid/zBylHDyVkwIfLLblM2KKxezYjQ+iR7camXc8sJ20H3Y    /ODDW4KOkIq2hk92Km7VVyECgYB70qEikCyulEWa/pwkSZYDnkHOLC/KT3hmr+4G    BXgCulMgmM5CdLK6XOpXRsFcTXdmS+KUft9j13aP6U1YhHa4Nv+jKBv/Nauo+rpK    V4M7m8ZmPuJdHl3tKVhbjrkXzQwYt0OK/eF4km0J9DxRxJhJqym1nm/n3Vcs38Ky    dDD02QKBgQCABfrSw4o445mkdB/PovK2eIH0GfZDTElVcORz7T4d27t1A+3XawEr    ll62cJyzSlUwNNQXjN7UjGn2qNuC6961BxzycXaTdNq7UOqeuWVbP+XCDiF6YVZq    0cwb19DSQaDY5Kw+R9GZ7QF5s1y/n2GLoBsoHazBBwu8cmOBLV5slQ==    -----END RSA PRIVATE KEY-----    kabdamatoAir:.ssh lcy$ 
0 0
原创粉丝点击