SSH Key相关问题
Contents
Summary
SSH Key分公钥和私钥, 私钥请自己妥善保管, 不要外泄。
另外采用ssh public key authentication是提升服务器安全与快捷措施之一。
Generate ssh key
以github为例使用ssh-keygen生成相对应的key
1 | # please make sure .ssh folder is exist |
Configure public key to Server
上传公钥到server有很多种方式了, 推荐使用ssh-copy-id
ssh-copy-id -i ~/.ssh/id_rsa.pub git@ip -p xx
有可能会遇到一些问题比如说: Permission denied (publickey).
或者bash: ssh-copy-id: command not found
If it’s permission problem, please check current user whether has execute privilege to .ssh
folder
Else if you use windows command line, maybe you didn’t install this tiny script, please execute the below script:
Maybe is works, good luck for you!
1 | GET_ID="cat ${ID_FILE}" |
scp ~/.ssh/ ~/.ssh/id_rsa.pub -p xx user@ip:
Attention please :
, then login server execute:
1 | cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys |
Keep safe authorized_keys
为了保证安全,您应该阻止其他用户添加新的公钥。
将 authorized_keys 的权限设置为对拥有者只读,其他用户没有任何权限:
1 | chmod 400 ~/.ssh/authorized_keys |
Disable password authentication
采用公钥登录server后, 最好禁用密码登录.
1 | vim /etc/ssh/sshd_config |
How to use in the tool
- 使用 alias
1 | $ cat ~/.bash_profile |
- 在 ssh client端import public key,这个就比较简单了。常用的客户端比如Putty, SecureCRT, XShell, Mobile client推荐JuiceSSH