# 安装 openssh 服务
sudo apt-get install openssh-server
# 启动 ssh 服务
sudo /etc/init.d/ssh start
# 若 firewalld 未安装,则先进行安装
sudo apt install firewalld
# 允许 tcp 22端口
sudo firewall-cmd --permanent --add-port=22/tcp
# 可选:允许ssh服务
sudo firewall-cmd --permanent --add-service=ssh
# reload 防火墙,应用规则
sudo systemctl reload firewalld
#验证22端口是否开启
sudo firewall-cmd --list-all
dujinwei@dujinwei-pc:~$ git config --global user.name "dujinwei"
dujinwei@dujinwei-pc:~$ git config --global user.email "[email protected]"
dujinwei@dujinwei-pc:~$ ssh-keygen -C '[email protected]' -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/dujinwei/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/dujinwei/.ssh/id_rsa
Your public key has been saved in /home/dujinwei/.ssh/id_rsa.pub
The key fingerprint is:
SHA256:D78Ugebp+lxSYmcoCZLeAfjGZ3GMrr4HQj07+eWN4JY 1979159182@qq.com
The key's randomart image is:
+---[RSA 3072]----+
| .. o |
|. oo o . |
| o+.oo o . |
| o+=+o + o . |
|...+= o S = |
|. o+ . = O . |
| o .+ = = = |
| . .E = = . |
| .o. ..o . |
+----[SHA256]-----+
dujinwei@dujinwei-pc:~$ cd ~/.ssh/
dujinwei@dujinwei-pc:~/.ssh$ ls
id_rsa id_rsa.pub known_hosts
dujinwei@dujinwei-pc:~/.ssh$ gedit id_rsa.pub
git config --global user.name "dujinwei"
git config --global user.email "[email protected]"
git init
git add STLDataStructure/
git commit -m "2021-01-20 第一次上传"
git status
git diff
git log #查看详细记录
git log --pretty=oneline #查看简单记录
git reset --hard HEAD^ #回到上一个版本
#上上一个版本就是 HEAD^^
#上一百个版本 HEAD~100
git reset --hard 566b #指定commit版本号 回退到指定的版本
git reflog #查看每一次操作命令
git diff HEAD -- hello.cpp #查看工作区和版本库里面最新版本的区别
git checkout -- hello.txt #撤销本地工作区的更改 不推荐
git restore hello.txt #撤销本地工作区的更改 新版本git
git restore --staged hello.txt #撤销缓冲区的更改 新版本git
ssh-keygen -t rsa -C "[email protected]"
git remote rm origin #删除
git remote add origin [email protected]:jermydu/STLDataStructure.git #添加
git push -u origin master #把内容推送到远程仓库,第一次推送
git push -f origin master #推送最新修改-f 强制覆盖
git clone [email protected]:jermydu/CppTemplateTutorial.git
#进入root
sudo bash
#安装git
apt-get install git
#安装ssh
apt-get install openssh-server openssh-client
#新建git用户
adduser dujinwei
#新建仓库
git init -bare /srv/dujinwei.git
#给用户授权git仓库权限
chown -R dujinwei:dujinwei /srv/dujinwei.git/
#安装git,本地新建文件夹作为本地目录
#clone仓库到本地
git [email protected]:/srv/dujinwei.git
(1)打开Windows PowerShell (管理员)
(2)输入 ssh-keygen.exe -t rsa
PS C:\Users\wangkun> ssh-keygen.exe -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (C:\Users\wangkun/.ssh/id_rsa):
Created directory 'C:\Users\wangkun/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in C:\Users\wangkun/.ssh/id_rsa.
Your public key has been saved in C:\Users\wangkun/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:WLV3969PxPSp6YaOLInkUetcambNCwxtWPGHnL5cIrQ wangkun@wangkun-pc
The key's randomart image is:
+---[RSA 2048]----+
| . . |
| +.o. |
| o.=... . o|
| =+o .. . ++|
| ooESo . .=|
| o+.o.+ o..|
| o =o*o .o o|
| o Xoo.... o |
| + .+o......|
+----[SHA256]-----+
PS C:\Users\wangkun>
Host dujinwei-linux #远程连接名 随便起
HostName 192.168.0.109 #远程主机IP地址
User dujinwei #远程主机登录用户名
dujinwei@dujinwei-pc:~$ cd .ssh/
dujinwei@dujinwei-pc:~/.ssh$ ls
id_rsa id_rsa.pub known_hosts
dujinwei@dujinwei-pc:~/.ssh$ vim authorized_keys
dujinwei@dujinwei-pc:~/.ssh$ cat authorized_keys
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDnsuUrTJT+4zR6azrbc5NSqj9VWP/3aN1M62TQfm3tLTqxBiF9rtI+3B7M8IenDH0GwiBk2Kk8n0zB0wNwJd0qt9EAVfT+FVZxuBHoOvzau1U/mp7tZsxjW/C6rUulMMz6XlD4Ym7LHwXE+nziECJziZVoGqwT1rRGl2OgN9grTtYZ4eOXEfBIUrXkpy08w3LMfveVlY+SaN+PZ9aWklGNVRLYQhiX6cbuVHAoIs0U81wWfaayuyHvXq3XqjON/RxPTTVuTiNimP/4W0KCMOkz5ecoJ/isgVAZw9rwg35kASERH4Rmv+Xvw7LxVhDVSBhvviDZKIwJhwBt/K3chZp1 wangkun@wangkun-pc