前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >12. Linux 介绍与工具使用(八:远程连接与文件传输介绍-SSH与SCP)

12. Linux 介绍与工具使用(八:远程连接与文件传输介绍-SSH与SCP)

作者头像
北野茶缸子
发布2021-12-17 09:30:35
7980
发布2021-12-17 09:30:35
举报
文章被收录于专栏:北野茶缸子的专栏

网络运维拓展知识

域名和IP地址

由一串用点分隔的名字组成,www.abc.com;是IP 地址的别名,方便记忆。

端口号

通过IP 地址可以找到网络上的计算机。通过端口号,则可以找到计算机上运行的程序。

访问域名

我们可以使用ping 命令来尝试访问网址:

代码语言:javascript
复制
$ ping www.baidu.com
PING www.a.shifen.com (36.152.44.95): 56 data bytes
64 bytes from 36.152.44.95: icmp_seq=0 ttl=56 time=11.452 ms
64 bytes from 36.152.44.95: icmp_seq=1 ttl=56 time=16.187 ms
64 bytes from 36.152.44.95: icmp_seq=2 ttl=56 time=12.856 ms
^C
--- www.a.shifen.com ping statistics ---
3 packets transmitted, 3 packets received, 0.0% packet loss
round-trip min/avg/max/stddev = 11.452/13.498/16.187/1.986 ms

我们可以尝试使用这个IP 在浏览器中访问一下试试:

因此我们通常使用域名来访问网址,也就是IP 地址的别名,否则太难记忆啦。

我们可以拆解一下访问域名/网站的过程:1)本地电脑,将访问指令传送给远程电脑;2)远程电脑上装有WEB 服务器,当我们将地址输入后,还需要设置一个端口,也就是上面提到的端口号,告诉远程电脑,我们需要访问装有WEB 服务器的软件,由该软件为访问者提供需要访问的内容;3)本地电脑获得远程电脑数据,加载想要访问的网页。

通常我们不指定端口,则会使用默认的端口。比如使用ssh,默认为22,访问web 服务器,默认为80。

如果我们给了一个错误的端口,则无法正常访问需要的服务了:

SSH

ssh,全称secure shell (SSH),是一种使用协议连接到远程计算机的软件程序。

SSH 目前较为可靠,专为远程登陆会话和其他网络服务提供安全性协议。

在mac os, ubuntu, linux 中,我们都是可以通过终端直接使用的:

通过网络,将客户端的指定,传输给服务器;服务器执行了指令后,通过网络,再将结果返回给客户端。实现远程的使用。

image.png

我们可以尝试一下ssh 远程访问自己的服务器,或者也可以创建一个虚拟机,用本地电脑访问虚拟机,关于授权信息,选择yes:

代码语言:javascript
复制
$ ssh mugpeng@192.168.130.128 -p 22
The authenticity of host '192.168.130.128 (192.168.130.128)' can't be established.
ECDSA key fingerprint is SHA256:uQKHuYrukuWxYAmR7owG6f+Xz7q2KD6a+lgxXbfLy6c.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.130.128' (ECDSA) to the list of known hosts.
mugpeng@192.168.130.128's password: 
Welcome to Ubuntu 20.04.1 LTS (GNU/Linux 5.8.0-41-generic x86_64)

 * Documentation:  https://help.ubuntu.com
 * Management:     https://landscape.canonical.com
 * Support:        https://ubuntu.com/advantage


243 updates can be installed immediately.
24 of these updates are security updates.
To see these additional updates run: apt list --upgradable

Your Hardware Enablement Stack (HWE) is supported until April 2025.
*** 需要重启系统 ***

The programs included with the Ubuntu system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Ubuntu comes with ABSOLUTELY NO WARRANTY, to the extent permitted by
applicable law.

# 成功进去啦
mugpeng@mugpeng-virtual-machine:~$ ls
Desktop  Documents  Downloads  Music  Pictures  Public  snap  Templates  Videos
mugpeng@mugpeng-virtual-machine:~$ 

SCP

其本质是一个远程拷贝的命令。你可以理解为服务器与服务器之间的复制粘贴。

image.png

端口也可以写成-oPort=

代码语言:javascript
复制
服务器使用scp下载和上传

• 下载
scp -oPort=6652 user@120.77.173.108:/path/filename /home/folder 
• 上传
scp -oPort=6652 /home/filename user@120.77.173.108:/path/folder

还可以指定-r 参数,对文件夹下载或上传(遍历文件)。

就是撸代码有点儿麻烦:

代码语言:javascript
复制
$ scp -r ~/Desktop appe@192.168.1.6:~/Desktop
Password:
test1.txt                                     100%    0     0.0KB/s   00:00    
本文参与 腾讯云自媒体同步曝光计划,分享自微信公众号。
原始发表:2021-10-15,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 北野茶缸子 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 网络运维拓展知识
    • 域名和IP地址
      • 端口号
        • 访问域名
        • SSH
        • SCP
        领券
        问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档