SSH是Secure Shell的简称,是一种加密的网络传输协议。
免密登录
将生成好的本机的公钥填写到服务器的/home/{username}/.ssh/authorized_keys文件中,如果没有该文件,创建一个,然后重启sshd服务。
这时就可以在本机通过ssh登录服务器了:
ssh username@hostname
多个秘钥
默认情况下,ssh会使用~/.ssh/id_rsa文件进行连接,但是很多情况下可能会在本机生成多个秘钥key pair。这个时候可以使用~/.ssh/config配置文件来指定各个主机的私钥文件:
Host {name}
HostName {hostname}
User {user name}
IdentityFile ~/.ssh/id_rsa1
Host {name}
HostName {hostname}
User {user name}
IdentityFile ~/.ssh/id_rsa2
对于非登录的情况,比如克隆git仓库,Host 和 HostName 不能随意指定,具体得看git托管平台的情况。比如github的设置:
Host github.com
HostName github.com
User git
IdentityFile ~/.ssh/xxx
更多
man ssh_config 5- [Secure Shell (简体中文)](https://wiki.archlinux.org/index.php/Secure_Shell_(%E7%AE%80%E4%BD%93%E4%B8%AD%E6%96%87)