道阻且长,行则将至,走慢一点没关系,不停下就好|

Ac_c0mpany丶

园龄:3年7个月粉丝:6关注:3

📂Linux
🔖Linux
2022-11-03 10:32阅读: 42评论: 0推荐: 0

【AcWing-Linux】04. SSH

SSH(Secure Shell,安全外壳协议)

一、SSH简介

SSH为建立在应用层和传输层基础上的安全协议(对数据进行加解密),专为远程登录会话和其他网络服务提供安全性的协议,可以有效防止远程管理过程中的信息泄漏问题,最初是UNIX系统上的一个程序。

二、SSH登录

2.1 基本用法
  • 远程登录服务器ssh user@hostname

user:用户名

hostname:IP地址或域名

第一次登录时会提示:

The authenticity of host '123.57.47.211 (123.57.47.211)' can't be established. ECDSA key fingerprint is SHA256:iy237yysfCe013/l+kpDGfEG9xxHxm0dnxnAbJTPpG8.Are you sure you want to continue connecting (yes/no/[fingerprint])?

输入yes,然后回车即可。

这样会将该服务器的信息记录在~/.ssh/know_hosts文件中

然后输入密码即可登录到远程服务器

  • 输入logoutexit:退出当前服务器

  • 默认登录端口号为22,如果想登录某一特定端口:ssh user@hostname -p 22

2.2 配置文件

创建文件~/.ssh/config

然后在文件中输入:

Host myserver1
    HostName IP地址或域名
    User 用户名

Host myserver2
    HostName IP地址或域名
    User 用户名

之后再用服务器时,可以用别名myserver1myserver2登录

2.3 秘钥登录

创建秘钥:ssh-keygen

然后一直回车

执行结束后,~/.ssh目录下会多两个文件:

  • id_rsa:私钥
  • id_rsa.pub:公钥

之后想免密登录哪个服务器,就将公钥传给服务器即可。


例如:想免密登录myserver服务器。则将公钥中的内容,复制到myserver中的~/.ssh/authorized_keys文件即可。

也可以使用如下命令一键添加公钥:ssh-copy-id myserver

2.4 执行命令

命令格式:ssh user@hostname command

例如:

ssh user@hostname ls -a

三、SCP(Secure Copy)传文件

3.1 SCP简介

SCP是用于远程拷贝文件,类似于本地拷贝文件命令cp,scp传输是加密传输,并且不占用系统资源。

3.2 基本用法

命令格式:scp source destination

source路径下的文件复制到destination


一次复制多个文件:

scp source1 source2 destination


复制文件夹:

scp -r ~/tmp myserver:/home/acs/

将本地家目录中的tmp文件夹复制到myserver服务器中的/home/acs/目录下

scp -r ~tmp myserver:homework/

将本地家目录中的tmp文件夹复制到myserver服务器中的~/homework/目录下

:默认是~/

scp -r myserver:homework .

myserver服务器中的~/homework/文件夹复制到本地的当前路径下。


指定服务器的端口号:

scp -P 22 source1 source2 destination

注意:scp-r -P等参数尽量加在sourcedestination之前


使用scp配置其他服务器的vimtmux

scp ~/.vimrc ~/.tmux.conf myserver:

本文作者:Ac_c0mpany丶

本文链接:https://www.cnblogs.com/keyongkang/p/16853599.html

版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。

posted @   Ac_c0mpany丶  阅读(42)  评论(0编辑  收藏  举报
点击右上角即可分享
微信分享提示
评论
收藏
关注
推荐
深色
回顶
收起
  1. 1 You Are My Sunshine REOL
You Are My Sunshine - REOL
00:00 / 00:00
An audio error has occurred.

作曲 : Traditional

You are my sunshine

My only sunshine.

You make me happy

When skies are gray.

You'll never know, dear,

How much I love you.

Please don't take my sunshine away

The other night, dear,

When I lay sleeping

I dreamed I held you in my arms.

When I awoke, dear,

I was mistaken

So I hung my head and cried.

You are my sunshine,

My only sunshine.

You make me happy

When skies are gray.

You'll never know, dear,

How much I love you.

Please don't take my sunshine away.

You are my sunshine,

My only sunshine

You make me happy

When skies are gray.

You'll never know, dear

How much I love you

Please don't take my sunshine away

Please don't take my sunshine away.

Please don't take my sunshine away.