ssh自动登陆

本文记录一些登陆的操作。

简化记录

1
2
ssh-keygen (一路回车)
ssh-copy-id latelee@172.18.18.18

ssh密钥登陆Linux服务

环境:windows+git bash+mingw (注:本文命令适用于Windows和Linux系统)

服务器:Linux CentOS 7

打开git bash,产生密钥对:

1
ssh-keygen -t rsa -b 4096

出现输入项时,直接回车即可。

1
2
3
Enter file in which to save the key (/c/Users/Late Lee/.ssh/id_rsa): // 回车
Enter passphrase (empty for no passphrase): // 回车
Enter same passphrase again: // 回车

最后输出目录:

1
2
Your identification has been saved in /c/Users/Late Lee/.ssh/id_rsa.
Your public key has been saved in /c/Users/Late Lee/.ssh/id_rsa.pub.

进入cd /c/Users/Late\ Lee/.ssh/目录。拷贝公钥到Linux服务器。

1
ssh-copy-id -i id_rsa.pub root@99.69.96.66

输出信息:

1
2
3
4
5
6
7
8
9
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "id_rsa.pub"
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
root@99.69.96.66's password: // !! 此处输入目标系统的密码

Number of key(s) added: 1

Now try logging into the machine, with: "ssh 'root@99.69.96.66'"
and check to make sure that only the key(s) you wanted were added.

输入ssh root@99.69.96.66,可以不需要密码登陆。

拷贝文件使用 scp 命令。在 Windows 系统可安装 cygwin 和 git 软件,以使用其提供的命令行。

  • 本文作者:李迟
  • 版权声明:原创文章,版权归署名作者,转载建议注明出处(当然不注明亦可)。
  • 本文链接:/devops/ssh-auto-login.html