免密登录设置

免密登录设置

Posted by Dongyupu on June 24, 2019
  • 部署任务通常需要从jenkins服务器使用scp命令来拷贝部署文件到测试环境的服务器,scp免密需要提前在测试服务器中将jenkins节点的ssh public key添加到信任名单中。

  • 具体步骤如下

  • 1.登录到你的测试服务器,编辑 ~/.ssh/authorized_keys 添加jenkins agent节点的ssh public key到该文件中 ~~~ #123.57.185.254/10.25.90.207 #cat ~/.ssh/id_rsa.pub ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDG5JaV/UzsbJn3VVL6duUujZKFB9ON4DdCuY0DyiWJIXD/lydCt7Ko6lXu9RnI/37yjdv0763+O+VdEAQl1RadgbyOPTrpDbiL6EdSL0VlL7M2Ry/G4kpltPFZPCklTxhglhX49PFH9QeyvdRpze8mk1Ekwsn/Ind4Evc8tERe/vks3n4GXczRrS9OQMgS23MtpyM9t9fLS19aUgLWLmW4LfJCnFj8emeZqQyi2ToL723ENTAivwKlEo739kv20oEBuYFq5BN6xtdmXuTyqc+hhinezFZ8pVvW1KwTicB8dBdFY4s+eyeoBXfzQ4JUm5UO9WhvlN3aQJ5AKP93h3pn root@iZ2zecny0ii2iu1xpvq67jZ

#192.168.1.42 #cat ~/.ssh/id_rsa.pub ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDTlNJfBiBtvour5gVsadxsTCnFwcmBlsangmZOYYNlqWaMvLPd7iFWkbYcs4hLETZ6sneduPGQHjlKFzJspTpMJLxZdSqsfOLL+5El9o6l32UohIfFeVx5qyAVdwEhISkvAcwKOITqqt2x3dnzYmOOkIZKa5WNVbA0CFLnqrBtwGjjUREvYSlz+vixEcfW6nbRfwUDlTqPWEAiouSJ6E0iCEuQeqCmPrzEV7t9x31cvl0DPjVMmSrYc0YgwbMv5vrQhVavrYUHpfEELsKVDe+EAuMNK00HAoelc9FlG4dCWBQVQuhKodtzkTd4w+FIJ9wFvwFuKn9Ul7lnYmm/PHgJ root@iz2zeihk6kfcls5kwmqzj1z

#jenkins master #cat ~/.ssh/id_rsa.pub ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDW/m8wbfaEtH8sl9rGjJXGdV6YbZVRrXveZGA6/C9dOTU6qXzfRqb87IKUFErKR415VSYGHvWTxt+8yWAMHG6/l0nj0YgjgCmfDklYyiY+tB/0/68P4wZsl/FrqDncy1ctUiJ32AQsiELzioL0js8vKyaOzZQ9cspoX2kV5kjXsWxmFJjNWAacAqgCfVzMqDfDOre/KVav4eLb60EizuTU0A4szYgDXVH6U5N0OWMVOvx0tvFzZYGkV2RUsGaiV7mdhExbLsdRsGUa1eZn4Z2Lu4yqikKUB9NyL5Bq2Xr0uyEp2JcVU6LoLlphBrMoRKL2UYVR2a31gE1wCrNIQJdJ root@iZ2ze2tzqe1llmfkszbkt8Z


* 2.修改authorized_keys 权限 为600

chmod 600 ~/.ssh/authorized_keys


* 3.登录并添加 known_hosts
* 在jenkins服务器上执行 ssh username@ip

[root@123.57.185.254/10.25.90.207 ]#ssh appuser@10.25.112.103

The authenticity of host ‘10.25.112.103 (10.25.112.103)’ can’t be established. RSA key fingerprint is SHA256:HD44RZ1QbVHdL3hEK85sHYGnqeDSVSsnBtkFVcL606M. RSA key fingerprint is MD5:8c:80:86:1d:6f:58:05:60:d9:3e:bc:71:6a:47:3b:40. Are you sure you want to continue connecting (yes/no)? yes Warning: Permanently added ‘10.25.112.103’ (RSA) to the list of known hosts. Last login: Thu Aug 23 10:31:43 2018 from 114.251.159.65

Welcome to Alibaba Cloud Elastic Compute Service !

[appuser@101.201.101.16/10.25.112.103 ~]$ ~~~

  • 至此,jenkins就可以免密登录你的测试服务器了!

  • Next

  • execute shell script on remote host useing ssh