- 两条centos7 192.168.228.141 k8sMaster , 192.168.228.139 jenkins
- jenkins 需要无密码在 k8sMaster 上执行sh 命令
- 在 jenkins 服务器上执行以下命令
# 进入用户目录下cd ~ # 查看是否呦.ssh文件夹ll -a# 如果没有 , 运行一下命令 ssh-keygen -t rsa # 有以下信息打印出来 , 直接回车 Generating public/private rsa key pair. Enter file in which to save the key (/root/.ssh/id_rsa): Created directory '/root/.ssh'. 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:Arl9gqhlG5hkk0qstfbS7eUKEUq7a2csLbRHUmhLLaA root@localhost.localdomain.jenkins_basic_139 The key's randomart image is:+---[RSA 2048]----+| ||o . . ||.Ooo+ ||E=*=o* ||=oX++ + S || =+*.o + ||..+*+ . . || =o*o o || ..* o.. |+----[SHA256]-----+ '# 这个时候在执行 获取公钥cat /root/.ssh/id_rsa.pub
在 k8sMaster上 执行
#进入用户目录cd ~ # 如果没有.ssh 那么自己新建一个cd .ssh # 新建文件vim authorized_keys # 将 Jenkins 服务器获取的公钥填写进去就行了
最后测试
# asdasd 随便写ssh root@192.168.228.141 asdasd # 返回这个 说明已经在 k8sMaster 上执行了命令 没有需要填写密码bash: asdasd: 未找到命令