Ubuntu 下连接Github

  Ubuntu下一直装着git,但却没怎么用过,因为连接到github一直没试,今天中午按着Github的指示一步步完成了连接。

  系统中首先得有ssh,没得话装一个。然后进入~/.ssh文件夹中,运行命令:

ssh-keygen -t rsa -C "your_email@example.com"

  途中会要求输入口令,空着好了,一路Enter。

1 eval "$(ssh-agent -s)"
2 ssh-add ~/.ssh/id_rsa

  安装xclip工具用来复制公钥:

1 sudo apt-get install xclip
2 xclip -sel clip < ~/.ssh/id_rsa.pub

  此时可以进入github的设置页面,在SSH keys中添加一个ssh key,直接ctrl v就可以把刚才的公钥加进去。

  这时就可以直接push到github了~

  而且要注意的是整个过程除了安装不要用sudo,否则ssh授权时候会混乱。我乱了后重弄了一遍,还是Permission denied,用ssh -vT git@github.com测试,还是Permission denied,重行ssh-add之后才正常。这里有官方的指导

 

  以上是用ssh方法连,还可以用https连接,其实https是官方推荐的。Linux下和Windows下授权方式不尽相同。

Linux下:

  • 输入命令:

    git config --global credential.helper cache
    # Set git to use the credential memory cache
    
  • 改变缓存时间为一个小时:

    git config --global credential.helper 'cache --timeout=3600'
    # Set the cache to timeout after 1 hour (setting is in seconds)

 Windows下:

posted @ 2014-08-25 18:31  hyace  阅读(1220)  评论(0编辑  收藏  举报