git ÔõÑùÐÞ¸Ä ssh
git ÊÇÏÖÔÚ³ÌÐòԱʹÓÃ×îƵÈԵĴúÂë°æ±¾ÖÎÀí¹¤¾ß£¬¶ø ssh ÊÇʵÏÖ git ´úÂëÍÆËͺÍÀÈ¡µÄÒªº¦ÈÏÖ¤·½·¨Ö®Ò»¡£¿ÉÊÇ£¬ÎÒÃÇÓÐʱ¼äÐèÒªÐÞ¸Ä ssh£¬ÔÚÕâƪÎÄÕÂÖУ¬ÎÒ½«»áΪÄúÌṩһЩ¹ØÓÚÔõÑùÐÞ¸Ä ssh µÄ¼òÆÓÒªÁ죬²¢Ú¹ÊÍ git ÈÏÖ¤Á÷³ÌµÄ»ù±¾ÖªÊ¶¡£
Git ÈÏÖ¤Á÷³Ì
ÔÚÏàʶÔõÑùÐÞ¸Ä SSH ֮ǰ£¬ÈÃÎÒÃÇÊ×ÏÈÏàʶһÏ Git ÔõÑùÈÏÖ¤ÄúµÄÉí·Ý¡£Git µ×²ãʹÓà Secure Shell£¨SSH£©¾ÙÐÐÇå¾²ÈÏÖ¤¡£SSH ÌṩÁËÒ»ÖÖ¼ÓÃܵÄͨѶÐÒ飬¿ÉÒÔ±£»¤Êý¾Ý´«ÊäÀú³ÌÖеÄÒþ˽ÐÔ¡¢ÍêÕûÐԺͿÉÑéÖ¤ÐÔ¡£ÔÚ Git µÄÉí·ÝÑéÖ¤Á÷³ÌÖУ¬SSH »áʹÓù«Ô¿¼ÓÃÜÊÖÒÕʵÏÖÉí·ÝÑéÖ¤£¬¼òÆÓµÄÁ÷³ÌÈçÏ£º
ÍâµØ Git ÔËÐÐ ssh-keygen ÌìÉúÒ»¸ö¹«Ô¿ºÍÒ»¸ö˽Կ.
½«¹«Ô¿Ìí¼Óµ½ÄúµÄ Git ÕË»§µÄ´æ´¢¿âµÄ SSH Key Ñ¡ÏÖÐ.
ÔÚ´Ó¿ÍÕ»À³ö´úÂë»òÕßÌá½»½ÓÂëʱ£¬Ê¹Óà SSH ¾ÙÐÐÉí·ÝÑéÖ¤, ÈôÊǹ«Ô¿ÄÜÓë˽ԿƥÅ䣬ÔòÉí·ÝÑéÖ¤ÀÖ³É.
£¨×¢£ºÈôÊÇÄúʹÓà HTTPS ÐÒé¾ÙÐÐ Git ͨѶ£¬ÔòÕâ¸öÀú³Ì²»Éæ¼° SSH ÈÏÖ¤¡£¶øÊÇÖ±½ÓʹÓÃÄú Git ÕË»§µÄÓû§ÃûºÍÃÜÂ룩
ÏÖÔÚÈÃÎÒÃÇ¿´Ò»ÏÂÔõÑùÐÞ¸Ä SSH¡£
ÐÞ¸Ä SSH µÄÒªÁì
ÐÞ¸Ä SSH ͨ³£ÓÐÁ½ÖÖÒªÁ죺һÖÖÊÇÖ±½Ó±à¼ SSH ÉèÖÃÎļþ£¬ÁíÒ»ÖÖÊÇͨ¹ý Git Bash ÔËÐÐ SSH ÏÂÁîÀ´ÉèÖá£ÎÒÃÇÒ»¸öÒ»¸öÀ´¿´¡£
µÚÒ»ÖÖÒªÁ죺ͨ¹ý±à¼ SSH ÉèÖÃÎļþÐÞ¸Ä SSH
ʹÓÃÎı¾±à¼Æ÷·¿ª SSH ÉèÖÃÎļþ£¬Windows Óû§Í¨³£ÔÚ C:\Users\Óû§Ãû.ssh Ŀ¼ÖУ¬Linux »ò Mac Óû§ÔòÔÚ ~/.ssh Ŀ¼ÖС£
ÈôÊÇÄúûÓÐÉèÖà SSH£¬Ôò ssh Îļþ¼Ð½«²»±£´æ£¬×î¼òÆÓµÄÒªÁìÊÇÔÚ Git Bash Öн¨ÉèÒ»¸ö SSH ÃÜÔ¿¡£ÔÚ Git Bash ÖÐÊäÈ룺
ssh-keygen -t rsa -C “ÄúµÄÓʼþµØµã”
ÔÚÄúµÄ Git ÕË»§Ò³ÃæÉϽ«¹«Ô¿Ìí¼Óµ½¡°SSHÃÜÔ¿¡±Ñ¡Ï£¬Äú¿ÉÒÔ·¿ª×Ô¼ºµÄÕË»§£¬Ñ¡ÔñsettingsÈ»ºóÑ¡ÔñSSH Keys,½«ÌìÉúµÄid_rsa.pub ¸´ÖƵ½SSH KeyÖм´¿É¡£
±à¼ config Îļþ¡£ÈôÊǸÃÎļþ²»±£´æ£¬Ôò¿ÉÒÔ½¨ÉèÒ»¸öÐÂÎļþ¡£ÓÉÓÚÕâÀï²»ÊÇÏÈÈÝ SSH µÄ»ù´¡ÖªÊ¶£¬ÎÒÃÇÖ»¼òÆÓÏÈÈÝͨ¹ýÏò config ÎļþÌí¼ÓÐÂÖ÷»úµÄÒªÁ죬ÒÔ±ãʹÓÃÐÂÉèÖÃÁýÕÖĬÈÏÉèÖá£
Host github.com
HostName github.com
User git
IdentityFile ~/.ssh/id_rsa_github
ÔÚÕâ¸öÉèÖÃÎļþÖУ¬ÎÒÃǽç˵ÁËÒ»¸öÐÂÖ÷»úµÄÃû³Æ£¬Ãû³ÆΪ github.com£¬Ö÷»úÃûΪ github.com£¬Óû§ÃûΪ git¡£IdentityFile Ñ¡ÏîÖ¸¶¨ÁËеÄ˽ԿÎļþµÄλÖá£
µÚ¶þÖÖÒªÁ죺ͨ¹ý Git Bash ÔËÐÐ SSH ÏÂÁîÉèÖà SSH
Æô¶¯ Git Bash¡£
ÔËÐÐ ssh-keygen ÏÂÁî¡£Ëü½«ÌáÐÑÄúÊäÈëеÄÎļþÃûºÍ·¾¶£¬»òÕßÄú¿ÉÒÔʹÓÃĬÈÏÉèÖá£
½«ÌìÉúµÄ¹«Ô¿Ìí¼Óµ½ÄúµÄ Git ÕË»§ÖУ¬»á¼û GitHub »òÆäËû Git ÍйÜЧÀͲ¢µÇ¼¡£
²âÊÔÐÂÃÜÔ¿ÊÇ·ñÆð×÷Óá£ÊäÈë ssh -T git@host£¬ÆäÖÐ host ÊÇÄúÏëÒª²âÊÔµÄÖ÷»úÃû¡£ÈôÊÇÒ»ÇÐÕý³££¬Äú»á¿´µ½Ò»¸ö½Ó´ýÐÂÎÅ£¬ÐÂΟæËßÄú£¬ÄúÒÑÅþÁ¬µ½ Git ÍйÜЧÀÍ¡£
ÒÔÉÏÊÇÁ½ÖÖͨ¹ýÐÞ¸Ä SSH À´Ö´ÐÐ Git Éí·ÝÑéÖ¤µÄ¼òÆÓÒªÁì¡£
½áÂÛ
SSH ÊÇ Git Çå¾²ÈÏÖ¤µÄÒªº¦£¬Ò²ÊÇ Git ÊÂÇéµÄÐëÒªÌõ¼þ¡£ÎÞÂÛÄúÊÇÐÂÊÖÕÕ¾É Git ÄÚÐУ¬ÏàʶÔõÑùÐÞ¸Ä ssh ¶¼ÊDZز»¿ÉÉٵġ£Ï£ÍûÉÏÊöÒªÁì¶ÔÄúÓÐËù×ÊÖú£¬¿ìÈ¥ÊÔÊÔ°É£¡
ÒÔÉϾÍÊÇgit ÔõÑùÐÞ¸Ä sshµÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡