linux之ssh方式登录

1.生成ssh秘钥文件
1、[root@localhost ~]# ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa): 
Created directory '/root/.ssh'.
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
87:83:55:c7:db:0a:df:93:7d:c5:c5:2d:06:59:25:b6 root@localhost.localdomain
The key's randomart image is:
+--[ RSA 2048]----+
|          ..o++oo|
|         . .o.oo+|
|        .    +Eo.|
|       o .. . . o|
|      . S .o o o.|
|         o  o + o|
|               ..|
|                 |
|                 |
+-----------------+

2、[root@localhost .ssh]# ls
id_rsa  id_rsa.pub

2. 安装登录用户的公钥
[root@localhost .ssh]# touch authorized_keys
[root@localhost .ssh]# cat /root/qqc_id_rsa.pub >> authorized_keys
3.设置文件执行权限
[root@host .ssh]$ chmod 600 authorized_keys
[root@host .ssh]$ chmod 700 ~/.ssh
4.重启ssh服务
[root@localhost .ssh]# service sshd restart
Redirecting to /bin/systemctl restart  sshd.service
5.ssh配置文件
[root@localhost .ssh]# vim /etc/ssh/sshd_config

允许root用户登录:
PermitRootLogin yes

注:禁用密码登录 PasswordAuthentication no
原文地址:https://www.cnblogs.com/quqinchao/p/13441768.html