OpenSSH作业

本文详细介绍了如何使用OpenSSH进行安全连接。首先通过ssh-keygen生成公钥-私钥对,接着使用ssh-copy-id将公钥部署到远程服务器,实现无密码登录。然后讲解了ssh命令用于无密码远程登录,以及scp命令的应用,包括上传文件到远程主机和从远程主机下载文件到本地。
摘要由CSDN通过智能技术生成

使用ssh-keygen 创建公钥-私钥对

(1)
[root@cwt ~]# 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:vUl2H5LJmVNSEbctRg38C6qJZsBMJcClRbHY0d15uMY root@cwt
The key's randomart image is:
+---[RSA 2048]----+
|  ..+*o . . o.*=.|
|   .=.oo . + +..+|
|   o oo   . + +o.|
|     .   . E X ..|
|    +   S = @ o .|
|     +   o = + o |
|      . . =   .  |
|       + o       |
|      o          |
+----[SHA256]-----+

(2)
[root@cwt-client ~]# 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:QkNdKNybvY5kKALhyv/liPvI3aq4KnX6Dh69f2KhkUA root@cwt-client
The key's randomart image is:
+---[RSA 2048]----+
|     ..o o.      |
|. E  .o +        |
|.o    o. +       |
|...  . .o .      |
|o. . ...S  .     |
|..o.= o.o .      |
| .++.+ = o       |
|..++=.B o .      |
|+ooOOOo=         |
+----[SHA256]-----+

使用ssh-copy-id 将公钥复制到远程系统上的正确位置

(1)
[root@cwt ~]# cd .ssh/
[root@cwt .ssh]# ls
id_rsa  id_rsa.pub  known_hosts
[root@cwt-server ~]# ssh-copy-id -i ~/.ssh/id_rsa.pub root@192.168.40.140
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/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@192.168.40.140's password: 

Number of key(s) added: 1

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

(2)
[root@cwt-client ~]# ssh-copy-id -i ~/.ssh/id_rsa.pub root@192.168.40.139
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/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@192.168.40.139's password: 

Number of key(s) added: 1

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


使用ssh命令无命令登入远程主机

(1)
[root@cwt-server ~]# ssh root@192.168.40.140
Last login: Mon Jul  1 20:20:47 2019 from 192.168.40.139
[root@cwt-client ~]# exit
登出

(2)
[root@cwt-client ~]# ssh root@192.168.40.139
Last login: Tue Jul  2 09:10:33 2019 from 192.168.40.140
[root@cwt-server ~]# exit
登出
Connection to 192.168.40.139 closed.

使用scp命令传送文件到远程主机

(1)
[root@cwt-server ~]# scp 2 root@192.168.40.140:/root
2                                                  100%    0     0.0KB/s   00:00    
[root@cwt-server ~]# ssh root@192.168.40.140
Last login: Mon Jul  1 20:27:26 2019 from 192.168.40.139
[root@cwt-client ~]# ls
1  anaconda-ks.cfg  httpd-2.4.34          Tetris.sh
2  chen.sh          httpd-2.4.34.tar.bz2  xiaochen.sh

(2)
[root@cwt-client ~]# scp 1 root@192.168.40.139:/root
1                                                 100%    0     0.0KB/s   00:00    
[root@cwt-client ~]# ssh root@192.168.40.139
Last login: Tue Jul  2 09:17:06 2019 from 192.168.40.140
[root@cwt-server ~]# ll
总用量 6820
-rw-r--r--.  1 root root        0 7月   2 09:17 1
-rw-r--r--.  1 root root        0 7月   1 20:29 2
-rw-------.  1 root root     1478 4月  12 10:43 anaconda-ks.cfg
-rw-r--r--.  1 root root      224 6月  27 15:30 chen.sh
drwxr-xr-x. 12  501 games    4096 6月  20 11:41 httpd-2.4.34
-rw-r--r--.  1 root root  6942969 6月  20 11:36 httpd-2.4.34.tar.bz2
-rwxr-xr-x.  1 root root    18681 4月  13 09:47 Tetris.sh
-rw-r--r--.  1 root root       57 6月  27 09:56 xiaochen.sh

使用scp命令从远程主机上下载文件到本地

(1)
[root@cwt-server ~]# scp root@192.168.40.140:/root/2 .
2                                                  100%    0     0.0KB/s   00:00    
[root@cwt-server ~]# ls
2                chen.sh       httpd-2.4.34.tar.bz2  xiaochen.sh
anaconda-ks.cfg  httpd-2.4.34  Tetris.sh

(2)
[root@cwt-client ~]# ls
2                chen.sh       httpd-2.4.34.tar.bz2  xiaochen.sh
anaconda-ks.cfg  httpd-2.4.34  Tetris.sh
[root@cwt-client ~]# scp root@192.168.40.139:/root/1 .
1                                                 100%    0     0.0KB/s   00:00    
[root@cwt-client ~]# ls
1  anaconda-ks.cfg  httpd-2.4.34          Tetris.sh
2  chen.sh          httpd-2.4.34.tar.bz2  xiaochen.sh

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值