SSH 免密登陆

免密登录设置:

  1. 进入到我的home目录  cd ~/.ssh
  2. 生成ssh免登陆秘钥ssh-keygen -t rsa (四个回车)执行完这个命令后,会生成两个文件id_rsa(私钥)、id_rsa.pub(公钥)
  3. 将公钥拷贝到要免登陆的机器上
  4. 将公钥添加到要免登陆机器的.ssh文件夹下的authorized_keys中,确保该文件权限为600. cat id_rsa.pub >> authorized_keys
//SSH client
[root@localhost ~]# cd .ssh
[root@localhost .ssh]# ls
authorized_keys  known_hosts
[root@localhost .ssh]# ssh-keygen -t rsa     <<< 默认是2024 -d 可以修改 -C 加注释
[root@localhost .ssh]# ls
authorized_keys  id_rsa  id_rsa.pub  known_hosts
[root@localhost .ssh]# scp id_rsa.pub root@10.124.45.85:/root
root@10.124.45.85's password: 
id_rsa.pub                                                                                           100%  408   134.2KB/s   00:00    

//SSH server
[root@localhost ~]# cat id_rsa.pub >> .ssh/authorized_keys 
[root@localhost ~]# 
           

1 comment

Comments feed for this article

  1. Linux’s avatar

    HI Xu

    For Line 8:
    you can use command:
    [root@localhost .ssh]#ssh-copy-id root@10.124.45.85
    then, you can login the 10.124.45.85 bypass password.

    Reply

Reply

Your email address will not be published.