iOS ssh keys 和 mac下使用github 上传代码

生成ssh keys

1.打开终端,输入:ssh-keygen -t rsa -C shw***@126.com,生成:
Generating public/private rsa key pair.
Enter file in which to save the key (/Users/wgj/.ssh/id_rsa): 此处可以自定义路径,不定义而点击回车就是默认的.ssh路径。下面自定义就输入:/Users/wgj/.wgjGithubSSh/wgjgithub_rsa,其中.wgjGithubSSh是建好的文件,wgjgithub_rsa,则是没有创建,生成后是文件的名字。

2.继续操作,输入两次密码,就在路径中有相应的东西了。

3.在github添加ssh key的时候,有两个地方需要操作,1.key的名字,这个可以以邮箱+mac名字,命名,便于以后的区分。2. 需要拷贝key,这个地方注意,不是拷贝文件,而是还有在终端中操作:
进入携带‘wgjgithub_rsa.pub’的文件夹(cd /Users/wgj/.wgjGithubSSh),然后:cat wgjgithub_rsa.pub,打开显示出来,发现是一大串,这才是需要拷贝的东西(公钥)(大串前面的ssh-rsa不要漏掉)。

打开终端,先测试一下你的帐号跟github连上没有:ssh -T git@github.com 如果出现如下提示,表示你连已经连上了.(因为有了第一步,所以不用自己做过多的连接github的操作了,另外,下一次要连接github的时候记得打开第一步的工具:sourcetree).
Hi wgj0909! You've successfully authenticated, but GitHub does not provide shell access.

如果输入$ ssh -T git@github.com
出现错误提示:Permission denied (publickey).因为新生成的key不能加入ssh就会导致连接不上github。

解决办法如下:
1.先输入$ ssh-agent,再输入$ ssh-add ~/.ssh/id_key,这样就可以了。--( ssh-add ~/.ssh/id_key:把专用密钥添加到 ssh-agent 的高速缓存中)
2.如果还是不行的话,输入ssh-add ~/.ssh/id_key 命令后出现报错Could not open a connection to your authentication agent.
  解决方法是key用Git Gui的ssh工具生成,这样生成的时候key就直接保存在ssh中了,不需要再ssh-add命令加入了,其它的user,token等配置都用命令行来做。
3.最好检查一下在你复制id_rsa.pub文件的内容时有没有产生多余的空格或空行,有些编辑器会帮你添加这些的。
Mac OS SSH密钥在重启后丢失的问题
1. 从macOS Sierra 10.12.2以后,SSH的配置选项中多了“UseKeychain”选项]
2. 要解决这个问题,就要借助于UseKeychain选项。在~/.ssh/config文件中添加下面这段话,问题就可以解决了:
Host *
   AddKeysToAgent yes
   UseKeychain yes
   IdentityFile ~/.ssh/id_rsa

在github下建自己的Repository。Create a New Repository,建好之后,可以具体操作了,下面是终端操作git上面的一些操作指令
touch README.md //新建一个记录提交操作的文档
git init //初始化本地仓库
git add README.md //添加
git commit -m "first commit"//提交到要地仓库,并写一些注释
git remote add origin git@github.com:youname/Test.git //连接远程仓库并建了一个名叫:origin的别名
git push -u origin master //将本地仓库的东西提交到地址是origin的地址,master分支下
git add * :添加所有的文件

还有一些错误:
如果输入$ Git remote add origin git@github.com:djqiang(github帐号名)/gitdemo(项目名).git

提示出错信息:fatal: remote origin already exists.

解决办法如下:

1、先输入$ git remote rm origin

2、再输入$ git remote add origin git@github.com:djqiang/gitdemo.git 就不会报错了!

3、如果输入$ git remote rm origin 还是报错的话,error: Could not remove config section 'remote.origin'. 我们需要修改gitconfig文件的内容

4、找到你的github的安装路径,我的是C:\Users\ASUS\AppData\Local\GitHub\PortableGit_ca477551eeb4aea0e4ae9fcd3358bd96720bb5c8\etc

5、找到一个名为gitconfig的文件,打开它把里面的[remote "origin"]那一行删掉就好了!

如果输入$ git push origin master

提示出错信息:error:failed to push som refs to .......

解决办法如下:

1、先输入$ git pull origin master //先把远程服务器github上面的文件拉下来

2、再输入$ git push origin master

3、如果出现报错 fatal: Couldn't find remote ref master或者fatal: 'origin' does not appear to be a git repository以及fatal: Could not read from remote repository.

4、则需要重新输入$ git remote add origingit@github.com:djqiang/gitdemo.git

//删除文件夹下的所有 .svn 文件
find . -name ".svn" | xargs rm -Rf
//删除文件夹下的所有 .git 文件
find . -name ".git" | xargs rm -Rf

其实,控制操作github,1.可以操作github里面具体页面,页面操作。2.可以用终端命令行。3.可以用sourceTree。

参考:http://blog.csdn.net/leikezhu1981/article/details/47664215

SSH keys
An SSH key allows you to establish a secure connection between your computer and GitLab.

Before generating an SSH key, check if your system already has one by running cat ~/.ssh/id_rsa.pub. If you see a long string starting with ssh-rsa or ssh-dsa, you can skip the ssh-keygen step.

To generate a new SSH key, just open your terminal and use code below. The ssh-keygen command prompts you for a location and filename to store the key pair and for a password. When prompted for the location and filename, you can press enter to use the default.

It is a best practice to use a password for an SSH key, but it is not required and you can skip creating a password by pressing enter. Note that the password you choose here can't be altered or retrieved.

ssh-keygen -t rsa -C "wangguanjun@rongzi.com"
Use the code below to show your public key.

cat ~/.ssh/id_rsa.pub
Copy-paste the key to the 'My SSH Keys' section under the 'SSH' tab in your user profile. Please copy the complete key starting with ssh- and ending with your username and host.

Use code below to copy your public key to the clipboard. Depending on your OS you'll need to use a different command:

Windows:

clip < ~/.ssh/id_rsa.pub
Mac:

pbcopy < ~/.ssh/id_rsa.pub
Linux (requires xclip):

xclip -sel clip < ~/.ssh/id_rsa.pub

Deploy keys
Deploy keys allow read-only access to multiple projects with a single SSH key.

This is really useful for cloning repositories to your Continuous Integration (CI) server. By using deploy keys, you don't have to setup a dummy user account.

If you are a project master or owner, you can add a deploy key in the project settings under the section 'Deploy Keys'. Press the 'New Deploy Key' button and upload a public SSH key. After this, the machine that uses the corresponding private key has read-only access to the project.

You can't add the same deploy key twice with the 'New Deploy Key' option. If you want to add the same key to another project, please enable it in the list that says 'Deploy keys from projects available to you'. All the deploy keys of all the projects you have access to are available. This project access can happen through being a direct member of the projecti, or through a group. See def accessible_deploy_keys in app/models/user.rb for more informati

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 194,911评论 5 460
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 82,014评论 2 371
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 142,129评论 0 320
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 52,283评论 1 264
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 61,159评论 4 357
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 46,161评论 1 272
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 36,565评论 3 382
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 35,251评论 0 253
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 39,531评论 1 292
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 34,619评论 2 310
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 36,383评论 1 326
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 32,255评论 3 313
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 37,624评论 3 299
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 28,916评论 0 17
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 30,199评论 1 250
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 41,553评论 2 342
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 40,756评论 2 335

推荐阅读更多精彩内容