Secure Shell (SSH) 是一個容許兩臺電腦之間經過安全的鏈接進行數據交換的網絡協議。經過加密保證了數據的保密性和完整性。SSH採用公鑰加密技術來驗證遠程主機,以及(必要時)容許遠程主機驗證用戶。html
一、傳統的FTP、Telnet是再網絡中明文傳送數據、用戶賬號和密碼,很容易受到中間人攻擊。而經過使用SSH,你能夠把全部傳輸的數據進行加密,這樣「中間人」這種攻擊方式就不可能實現了, 並且也可以防止DNS和IP欺騙。 二、第二個好處是:傳輸的數據是通過壓縮的,因此能夠加快傳輸的速度。git
SSH利用SSH Key來進行前面提到的基於密鑰的安全驗證。github
一、SSH-Key 就是一對密鑰對。【一個是公鑰,一個是私鑰】 二、公鑰是給別人用的。私鑰是給本身用的。 三、別人是誰?能夠是GitLab服務器。 本身是誰?能夠是本地。spring
四、舉個例子 4.1》本地想要使用git從gitHub/gitlab上拉取代碼。 4.2》給GitHub/GitLab配置公鑰,公鑰就能夠做爲一個加密的箱子,將代碼放在箱子裏。 4.3》被本地拉取到後,使用私鑰將加密的箱子打開。就能拿到代碼了。 4.4》整個過程當中,都沒有用戶名/密碼在網絡中傳輸,因此不會給他人攔截到,破解你的數據shell
五、因此,SSH-Key的直觀做用,就是【讓你方便的登陸到 SSH 服務器,而無需輸入密碼】vim
有RSA和DSA兩種認證密鑰windows
id_rsa :存放私鑰的文件centos
id_rsa.pub :存放公鑰的文件安全
known_hsots :能夠保存多個公鑰文件,每一個訪問過計算機的公鑰(public key)都記錄在~/.ssh/known_hosts文件中springboot
authorized_keys :A機器生成的公鑰-->放B的機器.ssh下authorized_keys文件裏,A就能免密訪問B,可是B不能訪問A。若是須要兩臺電腦互相訪問均免密碼。則須要重複上面的步驟(機器的配置恰好相反)。
[root@VM_0_6_centos ~]# netstat -anp|grep :22
tcp 0 0 0.0.0.0:22 0.0.0.0:*
tcp 0 36 172.16.0.6:22 211.161.248.60:22447
[root@VM_0_6_centos ~]# service sshd start
Redirecting to /bin/systemctl start sshd.service
複製代碼
[root@VM_0_6_centos .ssh]# cd /root/.ssh
[root@VM_0_6_centos .ssh]# ls
[root@VM_0_6_centos .ssh]#
複製代碼
郵箱能夠不是真實的。
[root@VM_0_6_centos .ssh]# ssh-keygen -t rsa -C "zhengja@dist.com"
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:ANbGYlsumXjZ3GzsgkCen80YNwl5Y1/U4zGgDcgaVIA zhengja@dist.com The key's randomart image is: +---[RSA 2048]----+ | o=B....oo | | E.*.@ +. = | | o + ^.B.... + | | = X B.* . | | + X +S | | = + . | | . | | | | | +----[SHA256]-----+ [root@VM_0_6_centos .ssh]# ls id_rsa id_rsa.pub [root@VM_0_6_centos .ssh]# 複製代碼
能夠配置gitlab、github、其它機器上等。
獲取公鑰(id_rsa.pub)內容
[root@VM_0_6_centos .ssh]# vim id_rsa.pub
複製代碼
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDMXYx0+V6xndjSdHpwOWqtqwQ2Wn95mFemNZuuKcILnqPP/bVJm3RKKmCu7jUqM2YgQOSEOAwdvKHTfKKFVLMXHvbKY63TdlrhvGZSXmsZPRVi3pxz2bZC+Wuxv3feVKypCWuHZBNjrmVylaDA7XcFwFrqH367621O/DIad1QgysXqX1ZhkL9SSlKVSowgyWcNvO3vXRkomg5oxiRCxhcuMsiN+WhJPuynNCMqPSIb/xNmX8lvXB2wTVqEnnlwsy849Mduv6g1I2OipOTUyDcEj8G+Tl4c44bYJKlyYxo7eF0MhZgAVpFBlcU+s/CpZfa4VdoOMehNr8NTUqxYbsmT zhengja@dist.com
Linux安裝git
[root@VM_0_6_centos local]# yum install git
[root@VM_0_6_centos local]# git --version
git version 1.8.3.1
複製代碼
配置git: email要和上名的配置一致(email能夠不是真實的)
[root@VM_0_6_centos ~]# git config --global user.name "zhengja"
[root@VM_0_6_centos ~]# git config --global user.email "zhengja@dist.com"
複製代碼
隨便找個本身gitlab上的項目
是否能下載gitlab項目
[root@VM_0_6_centos ~]# git clone ssh://git@elbgit-1200450932.cn-northwest-1.elb.amazonaws.com.cn:5337/zhengja/springboot-test-gitlab.git
Cloning into 'springboot-test-gitlab'...
The authenticity of host '[elbgit-1200450932.cn-northwest-1.elb.amazonaws.com.cn]:5337 ([52.83.120.124]:5337)' can't be established.
ECDSA key fingerprint is SHA256:cb3sC2zG1MwV8pkEZzfNzQ1V+3PZaEEc2UEdkHsdq2c.
ECDSA key fingerprint is MD5:be:bd:1d:07:f9:5e:27:25:6e:b5:af:e6:61:15:f8:d0.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '[elbgit-1200450932.cn-northwest-1.elb.amazonaws.com.cn]:5337,[52.83.120.124]:5337' (ECDSA) to the list of known hosts. remote: Counting objects: 22, done. remote: Compressing objects: 100% (13/13), done. remote: Total 22 (delta 0), reused 0 (delta 0) Receiving objects: 100% (22/22), done. [root@VM_0_6_centos ~]# ls springboot-test-gitlab 複製代碼
成功!
首先安裝git
默認位置:C:\Users\Administrator.ssh
在Windows下查看**[c盤->用戶->本身的用戶名->.ssh]*下是否有"id_rsa、id_rsa.pub"*文件,這兩個就是證書文件默認名稱。
安裝好git後:
右擊 空白處-->進入 Git Bash Here :郵箱能夠不是真實的
$ ssh-keygen -t rsa -C "zhengja@dist.com"
Generating public/private rsa key pair.
Enter file in which to save the key (/c/Users/Administrator/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /c/Users/Administrator/.ssh/id_rsa.
Your public key has been saved in /c/Users/Administrator/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:WDXfBdxE5au0AE0hCIE8u6aaqbQJIS883mBMNs4zm4k zhengja@dist.com The key's randomart image is: +---[RSA 2048]----+ | . .oo ..oo...=*| | + . .+o ..o.| | o .. .. . .| | . o . .| |o+ . . S . . . | |Oo.o o o | |o%+ o | |*=% | |EB . | +----[SHA256]-----+ 複製代碼
能夠配置gitlab、github、其它機器上等。
獲取公鑰(打開id_rsa.pub文件)內容
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDMXYx0+V6xndjSdHpwOWqtqwQ2Wn95mFemNZuuKcILnqPP/bVJm3RKKmCu7jUqM2YgQOSEOAwdvKHTfKKFVLMXHvbKY63TdlrhvGZSXmsZPRVi3pxz2bZC+Wuxv3feVKypCWuHZBNjrmVylaDA7XcFwFrqH367621O/DIad1QgysXqX1ZhkL9SSlKVSowgyWcNvO3vXRkomg5oxiRCxhcuMsiN+WhJPuynNCMqPSIb/xNmX8lvXB2wTVqEnnlwsy849Mduv6g1I2OipOTUyDcEj8G+Tl4c44bYJKlyYxo7eF0MhZgAVpFBlcU+s/CpZfa4VdoOMehNr8NTUqxYbsmT zhengja@dist.com
找的空文件夾-->右擊 空白處-->進入 Git Bash Here
Administrator@ZhengJiaAo MINGW64 /d/FileTest/Testgitlab
$ git clone ssh://git@elbgit-1200450932.cn-northwest-1.elb.amazonaws.com.cn:5337/zhengja/springboot-test-gitlab.git
Cloning into 'springboot-test-gitlab'...
remote: Counting objects: 22, done.
remote: Compressing objects: 100% (13/13), done.
remote: Total 22 (delta 0), reused 0 (delta 0)
Receiving objects: 100% (22/22), done.
複製代碼
成功!
例如:
windows經過Xshell 以ssh方式鏈接 Linux系統
Linux 以ssh鏈接另外一臺Linux系統
git使用ssh免密鏈接gitlab、github等下載項目
jenkins配置ssh鏈接slave節點機器 等等......