代码部署需要使用jenkins的Publish over SSH,为了方便配置一下jenkins的免密登录。

$ ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa): // 保存至哪个文件。
/root/.ssh/id_rsa already exists.
Overwrite (y/n)? y
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:
1a:d1:c7:ad:4e:89:0d:3e:17:c6:2f:37:0e:7f:54:8e root@iZm5egjqbdwtwlaqxtp1ldZ
The key's randomart image is:
+--[ RSA 2048]----+
|                 |
|       . o .     |
|      . o * .   .|
|       o * =   + |
|      . S O + E .|
|       o = * o   |
|      .   . o .  |
|             .   |
|                 |
+-----------------+

执行后得到公钥和私钥文件。

$ la .ssh
total 16K
-rw------- 1 root root  410 Sep 18 10:34 authorized_keys
-rw------- 1 root root 1.7K Sep 18 10:33 id_rsa
-rw-r--r-- 1 root root  410 Sep 18 10:33 id_rsa.pub
-rw-r--r-- 1 root root 1.6K Sep 18 10:08 known_hosts

查看公钥文件,将其复制到免密登录服务器的目标用户下的.ssh/authorized_keys中。

$ cat id_rsa.pub

之后再通过ssh登录目标服务器,就是免密的了。

最后修改日期: 2019年9月18日

作者

留言

撰写回覆或留言

发布留言必须填写的电子邮件地址不会公开。