ssh-keygen密钥生成免密登录

生成密钥

1
ssh-keygen -t rsa -f ~/.ssh/id_rsa -q -N ""

手动填写公钥

1
echo "ssh-rsa AAAAB3NzaC1yc2EAAAABJQAAAQEApmKkzrqBMypdNo0oG78IvW+zm2A5duadj7z89d6jam4xguYyZY5r5Ql+ZTJirKhV0hsGqqAIjia3iQ7GpmAqpBN5imJIDtuDldoJHatYiHhNRxQf/hQ/XTOcJg3MInyHLU7jcFsIHUi+CxSjJfR+SN3B0/dUl93g8khD562nQp8pMqIEEHF2qGMQ9O2KhpUvKfXJRYBGpyEJ8E+Hf/1SK2Bp++mWVuzGqaniktSy9XHtmnPujN0/rREwbO7NOsAhDpDR2OzoJba3AxIMCnYlU/FCrZ1GGEKi+reGk49Nommcxn+RCb9maiY+6g0aXu+tbXlRSaRjCUjPIidgRWps9w== rsa-key-20180502" > ~/.ssh/id_rsa.pub

上传密钥

1
cat ~/.ssh/id_rsa.pub | ssh -o StrictHostKeyChecking=no root@ip -p 端口 "mkdir -p ~/.ssh && touch ~/.ssh/authorized_keys && chmod -R go= ~/.ssh && cat >> ~/.ssh/authorized_keys"

提示输入VPS密码

坚持原创技术分享,您的支持将鼓励我继续创作!