SSH 免密码登录

来源:互联网 发布:巩义共赢网络是什么 编辑:程序博客网 时间:2024/04/25 13:42

每次登录远程服务器都要输密码!!!

这里写图片描述

事前准备

  • 本地机器:local

  • 远程机器:remote

实操步骤

  • 本地机器生成公钥,私钥: ssh-keygen -t rsa
fengyuruhui$ ssh-keygen -t rsaGenerating public/private rsa key pair.Enter file in which to save the key (/Users/chenshan/.ssh/id_rsa): /Users/chenshan/.ssh/id_rsa_testEnter passphrase (empty for no passphrase):Enter same passphrase again:Your identification has been saved in /Users/chenshan/.ssh/id_rsa_test.Your public key has been saved in /Users/chenshan/.ssh/id_rsa_test.pub.The key fingerprint is:SHA256:gYV/PFrA08nktGUZ8LlFJ/Fhg7wDRjYQslmwf4UYJZc taotao@mac007The key's randomart image is:+---[RSA 2048]----+|       =oXOO*o==.||      .oXoXE+=.+o||      .=.=+.+.o .||        o.= .=   ||        S= o. .  ||        . .      ||                 ||                 ||                 |+----[SHA256]-----+fengyuruhui$ ls ~/.ssh/ | grep testid_rsa_testid_rsa_test.pub
  • 上传本地公钥到远程机器: scp ~/.ssh/id_rsa_test.pub username@remote:.ssh/id_rsa_test.pub
fengyuruhui$  scp ~/.ssh/id_rsa_test.pub username@remote:.ssh/id_rsa_test.pubusername@remote's password:id_rsa_test.pub 
  • 在远程机器上设置 authorized_keys : cat /root/.ssh/id_rsa_test.pub >> /root/.ssh/authorized_keys
原创粉丝点击