JumperServer如何能够免密登录

JumperServer 免密登录

用了JumperServer后,每次要连远程服务器,需要选一次私钥文件,输入两次密码,输入一次ip,非常麻烦,能不能一个简短的指令就搞定呢?答案是可以的

简化步骤:

  1. 将jumperServer 私钥转换为 无密码私钥
  2. ssh-add 将私钥添加到 Keychain
  3. 设置命令 alias,简化命令

1. 将jumperServer 私钥转换为 无密码私钥

使用openssl将私钥转换为无密码私钥

# 指令
openssl rsa -in server.key -out server2.key
# 实际
openssl rsa -in shenlongguang_aliyun.pem -out shenlongguang_aliyun_passwordless.pem

2. ssh-add 将私钥添加到 Keychain

ssh-add -k /Users/sloong/Documents/company/analysys/jumperServerKeys/shenlongguang_aliyun_passwordless.pem

如果出现下面异常,则是私钥文件的权限问题:

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@         WARNING: UNPROTECTED PRIVATE KEY FILE!          @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Permissions 0644 for '/Users/sloong/Documents/company/analysys/jumperServerKeys/shenlongguang_aliyun_passwordless.pem' are too open.
It is required that your private key files are NOT accessible by others.
This private key will be ignored.

# 修改文件权限
chmod 700 shenlongguang_aliyun_passwordless.pem

3. 设置命令 alias,简化输入

修改 ~/.zshrc 文件(bash 也差不多),增加 下列 alias:

alias ssh-add-ali='ssh-add -k /Users/sloong/Documents/company/analysys/jumperServerKeys/shenlongguang_aliyun_passwordless.pem'
alias ssh-ali='ssh shenlongguang@123.56.25.ip'


这样执行 ssh-add-ali 就可以直接添加私钥到 Keychain(重启后执行一次即可,重启后会失效)。下次需要ssh 到远程服务器 只需要执行 ssh-ali 即可,ip/密码什么都不用输入

~ ssh-add-uc
Identity added: /Users/sloong/xxx/shenlongguang_aliyun_passwordless.pem)
~ ssh-ali
Last login: Wed May  3 09:25:25 2017 from 218.76.1.ip

Welcome to aliyun Elastic Compute Service!
......

 
Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×