Generating public/private rsa key pair.> Enter a file in which to save the key (/home/you/.ssh/id_rsa): [Press enter]> Enter passphrase (empty for no passphrase): [Typ_attempts to s">
赞
踩
- ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
- > Generating public/private rsa key pair.
- > Enter a file in which to save the key (/home/you/.ssh/id_rsa): [Press enter]
- > Enter passphrase (empty for no passphrase): [Type a passphrase]
- > Enter same passphrase again: [Type passphrase again]
可以按照默认路径和文件生成,路径位于home/xxx/.ssh/id_rsa,如果输入文件名后会将公钥和私钥文件保存到当前目录下。
然后启动ssh代理并且将私钥添加到代理
- $ eval "$(ssh-agent -s)"
- > Agent pid 59566
- ssh-add ~/.ssh/id_rsa
然后打开公钥(.pub文件)并复制或用命令行
- $ sudo apt-get install xclip
- # Downloads and installs xclip. If you don't have `apt-get`, you might need to use another installer (like `yum`)
- $ xclip -sel clip < ~/.ssh/id_rsa.pub
- # Copies the contents of the id_rsa.pub file to your clipboard
登陆Github后选择设置下 SSH and GPG keys,选择SSH key添加,名字随意,粘贴公钥。
最后:测试SSH连接成功!
- ssh -T git@github.com
- # Attempts to ssh to GitHub
- Warning: Permanently added the RSA host key for IP address '140.82.121.3' to the list of known hosts.
- Hi xxx! You've successfully authenticated, but GitHub does not provide shell access.
进入你想保存的目录下打开终端
- git init
- git add .
- #添加所有文件
- git commit -m "Initial commit"
- git remote add origin https://github.com/xxx/repo_test.git
将本地仓库关联到远程仓库,如果显示已存在origin,删除所有源
- git remote rm origin
- git remote -v
- #查看是否正确
最后一步上传到远端
git push origin master
- git add .
- #确保上传所有文件
-
- git commit -m "20201020 username"
-
- git remote -v
- #查看origin位置是否正确
-
- eval "$(ssh-agent -s)"
- #启动SSH客户端
- > Agent pid 59566
-
- ssh-add ~/.ssh/ratslam
- #添加你的私钥文件名称
-
- ssh -T git@github.com
- #测试连接是否成功
- > Hi XXX! You've successfully authenticated, but GitHub does not provide shell access.
- git push origin master
- #最后一步执行上传操作
因为ssh代理只对当前终端有效,因此需要在这里启动终端!
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。