SSHÔõÑùÉèÖÃGit
ÔÚʹÓÃgit¾ÙÐа汾¿ØÖƵÄÀú³ÌÖУ¬sshÓÃÓÚÇå¾²µØÅþÁ¬µ½Ð§ÀÍÆ÷ºÍ´æ´¢¿â¡£ÈôÊÇÄãÏëҪʹÓÃsshÀ´ÅþÁ¬µ½´æ´¢¿âºÍ¾ÙÐÐpushºÍpull²Ù×÷£¬ÄãÐèÒªÏȾÙÐÐssh ÉèÖá£
ÏÂÃæÊÇSSHÉèÖÃGitµÄ°ì·¨£º
1.ÌìÉúSSHÃÜÔ¿
ҪʹÓÃSSHÅþÁ¬µ½Git´æ´¢¿â£¬ÄãÐèÒªÌìÉúSSHÃÜÔ¿²¢½«ÆäÌí¼Óµ½ÄãµÄGitÕÊ»§ÖС£
ÒªÌìÉúSSHÃÜÔ¿£¬Çë·¿ªÖն˲¢ÊäÈëÒÔÏÂÏÂÁ
ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
µÇ¼ºó¸´ÖÆ
Õâ¸öÏÂÁÌìÉúÒ»¸öSSHÃÜÔ¿¶Ô£¬°üÀ¨Ò»¸ö¹«Ô¿£¨id_rsa.pub£©ºÍÒ»¸ö˽Կ£¨id_rsa£©¡£Çë×¢ÖØ£¬ÉÏÃæµÄÏÂÁî·ºÆðµÄyour_email@example.comÓ¦¸ÃÌ滻ΪÄã×Ô¼ºµÄµç×ÓÓʼþµØµã¡£
°´»Ø³µ¼üºó£¬Ä㽫±»ÒªÇóÊäÈëÎļþÃûºÍÃÜÂë¡£ÈôÊÇÄã²»ÏëΪÄãµÄÃÜÔ¿ÉèÖÃÃÜÂ룬Äã¿ÉÒÔÖ±½Ó°´»Ø³µ¼üÌø¹ý¡£
2.Ìí¼Ó¹«Ô¿µ½ÄãµÄGitÕË»§
ÔÚÄãʹÓÃSSHÅþÁ¬µ½Git´æ´¢¿â֮ǰ£¬ÄãÐèÒª½«¹«Ô¿Ìí¼Óµ½ÄãµÄGitÕË»§ÖС£ÕâÑù£¬Git¾Í»áÈÏ¿ÉÄãµÄSSHÃÜÔ¿£¬²¢ÊÚȨÄã¾ÙÐÐpushºÍpull²Ù×÷¡£
Òª½«¹«Ô¿Ìí¼Óµ½ÄãµÄGitÕË»§£¬ÇëÏȸ´Öƹ«Ô¿¡£·¿ªÖն˲¢ÊäÈëÒÔÏÂÏÂÁ
cat ~/.ssh/id_rsa.pub
µÇ¼ºó¸´ÖÆ
¸ÃÏÂÁÏÔʾÄãµÄ¹«Ô¿¡£Ç뽫ËùÓÐÄÚÈݸ´ÖƵ½ÄãµÄGitÕË»§ÖС£·¿ªÄãµÄGitÕË»§£¬²¢ÔÚÒ³ÃæµÄÓÒÉϽÇÑ¡Ôñ¡°Settings¡±>¡°SSH and GPG keys¡±>¡°New SSH key¡±¡£
ÔÚ¡°Title¡±×Ö¶ÎÖÐÊäÈëÒ»¸öÐÎòÐÔµÄÃû³Æ£¨ÀýÈç¡°×Ô¼ºµÄÃÜÔ¿¡±£©£¬È»ºó½«ÄãµÄ¹«Ô¿¸´ÖƵ½¡°Key¡±×Ö¶ÎÖС£µ¥»÷¡°Add SSH key¡±°´Å¥£¬ÄãµÄ¹«Ô¿¾Í±»Ìí¼Óµ½ÄãµÄGitÕË»§ÖÐÁË¡£
3.ʹÓÃSSHÅþÁ¬µ½Git´æ´¢¿â
ÏÖÔÚÄãÒѾÌìÉúÁËSSHÃÜÔ¿²¢½«¹«Ô¿Ìí¼Óµ½ÁËÄãµÄGitÕË»§ÖУ¬Äã¿ÉÒÔʹÓÃSSHÅþÁ¬µ½Git´æ´¢¿â²¢¾ÙÐÐpushºÍpull²Ù×÷¡£
ҪʹÓÃSSHÅþÁ¬µ½Git´æ´¢¿â£¬ÇëÊ×ÏÈ»ñÈ¡´æ´¢¿âµÄSSH URL¡£ÔÚÄãµÄGit´æ´¢¿âÒ³ÃæÖУ¬µ¥»÷¡°Clone or download¡±°´Å¥£¬²¢È·±£¡°Clone with SSH¡±Ñ¡ÏîÊÇÑ¡Öеġ£Ä㽫¿´µ½¸Ã´æ´¢¿âµÄSSH URL£¬¿ÉÒÔ½«Æ临ÖƵ½¼ôÌù°åÖС£
·¿ªÖնˣ¬½øÈëÄã´æ´¢´úÂëµÄĿ¼²¢ÊäÈëÒÔÏÂÏÂÁ
git remote set-url origin git@github.com:yourusername/yourrepository.git
µÇ¼ºó¸´ÖÆ
ÉÏÃæµÄÏÂÁî»á½«Äã´æ´¢´úÂëµÄ´æ´¢¿âÓëSSH URLÏà¹ØÁª£¬ÕâÑùÄã¾Í¿ÉÒÔʹÓÃSSHÅþÁ¬µ½¸Ã´æ´¢¿â¡£
ÏÖÔÚ£¬Äã¿ÉÒÔʹÓÃSSHÅþÁ¬µ½¸Ã´æ´¢¿â£¬²¢¾ÙÐÐpushºÍpull²Ù×÷¡£ÀýÈ磬Ҫ½«ÄãµÄ´úÂëÍÆË͵½Git´æ´¢¿â£¬ÇëʹÓÃÒÔÏÂÏÂÁ
git push -u origin master
µÇ¼ºó¸´ÖÆ
ÉÏÃæµÄÏÂÁî»á½«ÄãµÄ´úÂëÍÆË͵½Git´æ´¢¿â£¬²¢½«ÆäÓë¡°master¡±·ÖÖ§Ïà¹ØÁª¡£µÚÒ»´ÎÍÆËÍʱ£¬ÇëʹÓÃ-uÑ¡ÏÒÔ±ãÔÚδÀ´µÄÍÆËͲÙ×÷Öн«ÄãÍâµØµÄmaster·ÖÖ§ÓëÔ¶³ÌµÄmaster·ÖÖ§Ïà¹ØÁª¡£
½áÂÛ
ÔÚʹÓÃGitʱ£¬SSHÊÇÒ»¸öºÜÊÇÓÐÓõŤ¾ß£¬¿É×ÊÖúÄãÇå¾²µØÅþÁ¬µ½Ð§ÀÍÆ÷ºÍ´æ´¢¿â¡£Í¨¹ýƾ֤ÉÏÃæµÄ°ì·¨¾ÙÐÐÉèÖã¬Äã¿ÉÒÔÇáËɵØʹÓÃSSHÅþÁ¬µ½Git´æ´¢¿â£¬²¢¾ÙÐÐpushºÍpull²Ù×÷¡£
ÒÔÉϾÍÊÇSSHÔõÑùÉèÖÃGitµÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡