ssh 免密登录远程服务器

用的是mac系统,终端用的是iterm2,免密登录实际上使用的是ssh的公钥放到目标服务器上,用户可以通过私钥免密登录服务器上。
首先要生成自己的密钥对:

ssh-keygen
#需要我们确认,安全起见会让你输入密码,本例为不输入密码,直接回车跳过即可。
#生成完成后可以在~/.ssh 目录下看到相应的id_rsa 文件和id_rsa.pub文件。

其次我们需要配置远程登录的别名,方便我们ssh的时候知道访问哪个服务器:

#增加配置信息
vim ~/.ssh/config
#增加如下内容
Host  test-110
  Hostname 10.180.170.110
  User shibinbin

然后将公钥推送到目标服务器上

ssh-copy-id test-110
#如下内容代表成功
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/Users/shibinbin/.ssh/id_rsa.pub"
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
[email protected]'s password:

Number of key(s) added:        1

Now try logging into the machine, with:   "ssh 'test-110'"
and check to make sure that only the key(s) you wanted were added.

此时我们可以在终端使用ssh直接免密登录了:

ssh test-110

你可能感兴趣的:(ssh 免密登录远程服务器)