openssh

手动配置ssh

创建公钥-私钥对(客户机)

[root@kehuji ~]# ssh-keygen -t rsa
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:
SHA256:3Wv4KZmgFhs5dBqoS/1RzsX2xs5R/CB80a1tPfVhvO8 root@kehuji
The key's randomart image is:
+---[RSA 2048]----+
|              ...|
|              .++|
|     .   . . ..+*|
|    . o o.+.o *o=|
|   o . OSo.o.+ +o|
|  o . B +  .=.  o|
| . . . B ..*o. . |
|  .   =   +oo.  E|
|     .     .o    |
+----[SHA256]-----+

将公钥复制到远程主机上

[root@kehuji ~]# cd .ssh/
[root@kehuji .ssh]# ls
id_rsa  id_rsa.pub
[root@kehuji .ssh]# ssh-copy-id -i id_rsa.pub root@192.168.194.129
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "id_rsa.pub"
The authenticity of host '192.168.194.129 (192.168.194.129)' can't be established.
ECDSA key fingerprint is SHA256:iYay6JB/dzmh28KVizE/kWaQsikP5hAmeH7hKkFRfts.
ECDSA key fingerprint is MD5:0a:d2:3d:59:98:3b:7e:37:3f:be:98:7d:65:de:0c:3d.
Are you sure you want to continue connecting (yes/no)? yes
/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@192.168.194.129's password: 

Number of key(s) added: 1

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

远程连接服务器

[root@kehuji .ssh]# ssh root@192.168.194.129
Last login: Tue Oct 22 14:10:01 2019 from 192.168.194.1
[root@service ~]# 

使用scp方法连接

创建公钥-私钥对

[root@kehuji ~]# ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa): 
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:
SHA256:LSe8hoP2IXRIoCRhMQ0W2BWCitIvofKtIwntjBEkcbk root@kehuji
The key's randomart image is:
+---[RSA 2048]----+
|=&Ooo.           |
|O+++             |
|*. ..            |
|= E. . . .       |
|.+ oo . S o      |
|= o..o . =       |
|oB o+ + o        |
|+ =..o +         |
| ..o  .          |
+----[SHA256]-----+

将公钥发送个服务端

[root@kehuji ~]# cd .ssh/
[root@kehuji .ssh]# 
[root@kehuji .ssh]# ls
id_rsa  id_rsa.pub  known_hosts
[root@kehuji .ssh]# scp id_rsa.pub root@192.168.194.129:/root/.ssh/authorized_keys
root@192.168.194.129's password: 
id_rsa.pub                               100%  393   175.7KB/s   00:00    
[root@kehuji .ssh]# 

在服务器端修改文件权限为600 目录权限为700

[root@service .ssh]# ll
总用量 4
-rw-r--r--. 1 root root 393 10月 22 14:28 authorized_keys
[root@service .ssh]# chmod 600 authorized_keys 
[root@service .ssh]# ll
总用量 4
-rw-------. 1 root root 393 10月 22 14:28 authorized_keys
[root@service .ssh]# 

测试远程登录

[root@kehuji .ssh]# ssh root@192.168.194.129
Last login: Tue Oct 22 14:31:46 2019 from 192.168.194.128
[root@service ~]# 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值