SSH客户端会话超时的解决方案

背景

通常默认公有云上的ECS远程连接,很容易断开,当你有什么事情被打断或者去操作别的机器同步做点其他事情,你会发现你SSH客户端登录窗口经常会断开掉,非常烦人,经常要重新登录。
如果用一些Windows下客户端软件比如XShell or CRT都会有超时时间和心跳检测次数设置,但是默认Mac下的终端 Or Linux下直接远程命令客户端是没有这个设置窗口的。
SSH Client会从以下途径获取配置参数:

  1. SSH命令行参数;
  2. 用户配置文件 (~/.ssh/config);
  3. 系统配置文件 (/etc/ssh/ssh_config)。

方法1

1
ssh -o ServerAliveInterval=60 -o ServerAliveCountMax=30 root@10.0.1.25 -p22

方法2

1
2
3
4
$ vim ~/.ssh/config #添加如下内容
Host *
ServerAliveInterval 60
ServerAliveCountMax 30

方法3

1
2
3
4
5
6
$ vim /etc/ssh/ssh_config # 在Host *下面添加:

Host *
SendEnv LANG LC_*
ServerAliveInterval 60
ServerAliveCountMax 30

如果三个都设置了,读取顺序是 方法1 —> 方法2 —> 方法3

论文学习 - Bitcoin:A Peer-to-Peer Electronic Cash System(10)

比特币:一个点对点的电子货币系统

11 结论

11 Conclusion
We have proposed a system for electronic transactions without relying on trust. We started with the usual framework of coins made from digital signatures, which provides strong control of ownership, but is incomplete without a way to prevent double-spending. To solve this, we proposed a peer-to-peer network using proof-of-work to record a public history of transactions that quickly becomes computationally impractical for an attacker to change if honest nodes control a majority of CPU power. The network is robust in its unstructured simplicity. Nodes work all at once with little coordination. They do not need to be identified, since messages are not routed to any particular place and only need to be delivered on a best effort basis. Nodes can leave and rejoin the network at will, accepting the proof-of-work chain as proof of what happened while they were gone. They vote with their CPU power, expressing their acceptance of valid blocks by working on extending them and rejecting invalid blocks by refusing to work on them. Any needed rules and incentives can be enforced with this consensus mechanism.

我们已经提出了一种不依赖信任的电子交易系统。我们从通用的数字签名货币体系开始,这体系提供了强有力的所有权控制,但由于缺乏防止双重支付的方法而不完善。为解决这个问题,我们提出一种使用工作量证明来记录公共交易历史的点对点网络,只要诚实节点控制了多数的 CPU 算力,对于攻击者,交易历史将很快变得在计算上不可更改。网络因其结构简洁性而强大。节点只需很少的协调就能同时工作。它们不需要被认证,因为信息不会被发送到某个特殊的位置,只需被尽力传播。节点可以随时离开和重新加入网络,只需接受工作量证明链作为它们离开时发生事件的证据。节点使用 CPU 算力来投票,通过致力于延长有效区块来表达对其接受,通过拒绝在无效区块上工作来表达对其抵制。任何需要的规则和激励都可通过这个共识机制来加强。

【关注点】:

  • rules and incentives, 都会有哪些规则和激励?

论文学习 - Bitcoin:A Peer-to-Peer Electronic Cash System(9)

比特币:一个点对点的电子货币系统

11 计算

We consider the scenario of an attacker trying to generate an alternate chain faster than the honest chain. Even if this is accomplished, it does not throw the system open to arbitrary changes, such as creating value out of thin air or taking money that never belonged to the attacker. Nodes are not going to accept an invalid transaction as payment, and honest nodes will never accept a block containing them. An attacker can only try to change one of his own transactions to take back money he recently spent.
The race between the honest chain and an attacker chain can be characterized as a Binomial Random Walk. The success event is the honest chain being extended by one block, increasing its lead by +1, and the failure event is the attacker’s chain being extended by one block, reducing the gap by -1. The probability of an attacker catching up from a given deficit is analogous to a Gambler’s Ruin problem. Suppose a gambler with unlimited credit starts at a deficit and plays potentially an infinite number of trials to try to reach breakeven. We can calculate the probability he ever reaches breakeven, or that an attacker ever catches up with the honest chain, as follows [8]:
p = probability an honest node finds the next block
q = probability the attacker finds the next block
qz = probability the attacker will ever catch up from z blocks behind

More...

Difference between" npm run serve" and "npm run dev" in VUE

npm run serve basically is just saying “npm please run the command I defined under the name serve in package.json” the same happens with npm run dev.

Given this the commands can do the exact same thing, similar things, or very different things. Usually they are a shorthand for running a dev server on localhost, but it’s not a rule, only a convention.

So you’ll need to check in your package.json file and look for

1
2
3
4
"scripts": {
"serve": "[list of commands here]",
"dev": "[list of commands here]"
},

VUE练习4 - 使用Ant Design

1 安装

1
npm i --save ant-design-vue@3.2.16

不要装最新版,变化比较大。

2 注册

**全局完整注册:**修改 main.js:

1
2
3
4
5
6
7
8
9
10
11
import { createApp } from 'vue';
import App from './App.vue';
import router from './router';
import store from './store';
import Antd from "ant-design-vue";
import "ant-design-vue/dist/antd.css";
import settings from '@/settings';

const app = createApp(App)
app.use(store).use(router).use(Antd).mount('#app')
app.config.globalProperties.$settings = settings

3 测试

修改 ShowCenterView.vue

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
<template>
<div class="showcenter">
<h1>show center | 展示中心</h1>
<a-row>
<a-col :span="8" :offset="8">
<a-input-search
v-model:value="value"
placeholder="input text"
enter-button="Search"
size="large"
@search="onSearch"
/>
</a-col>
</a-row>
</div>
</template>

效果:

论文学习 - Bitcoin:A Peer-to-Peer Electronic Cash System(8)

比特币:一个点对点的电子货币系统

10 隐私

10 Privacy
The traditional banking model achieves a level of privacy by limiting access to information to the parties involved and the trusted third party. The necessity to announce all transactions publicly precludes this method, but privacy can still be maintained by breaking the flow of information in another place: by keeping public keys anonymous. The public can see that someone is sending an amount to someone else, but without information linking the transaction to anyone. This is similar to the level of information released by stock exchanges, where the time and size of individual trades, the “tape”, is made public, but without telling who the parties were.

As an additional firewall, a new key pair should be used for each transaction to keep them from being linked to a common owner. Some linking is still unavoidable with multi-input transactions, which necessarily reveal that their inputs were owned by the same owner. The risk is that if the owner of a key is revealed, linking could reveal other transactions that belonged to the same owner.

传统的银行模型通过限制参与方和可信任第三方对信息的访问来达到一定级别的隐私保护。交易必须要公开发布就不能使用这个方法,但隐私仍可在其他地方通过阻断信息流的方式来保护:那就是保持公钥匿名。公众能看到有人正在发送一定量货币给其他人,但是不能将交易关联到某个人。这和证券交易所发布的信息级别类似,每笔交易的时间和交易量,即行情是公开的,但是不会显示交易双方是谁。

作为额外的防火墙,对每笔交易使用新密钥对可以防止他们被关联到一个共同的拥有者。由于多输入值交易存在,有些关联仍不可避免,因为多输入值交易必然暴露其多个输入是属于同一个拥有者的。风险就在于如果一个密钥的拥有者被暴露,关联性将暴露属于同一个拥有者的其他交易。

【关注点】:

  • keeping public keys anonymous, 如何做到呢?
  • 证券交易所发布的信息级别类似,这个类比比较有趣。

VUE练习2 - 使用axios模块

1 安装axios

1
2
项目根目录下执行如下指令
npm install -S axios --registry https://registry.npm.taobao.org

2 修改模块代码

在开发过程中,我们可能经常会在前端项目的业务里面使用到某些变量,我们可以添加到配置文件中,比如我们在src目录下创建一个settings.js文件:

/settings.js

1
2
3
export default { // 注意,对象要抛出后,其他文件中才能引入使用
host: 'http://api.yunminitools.cn:8000' // 我们的后台项目将来就通过这个域名和端口来启动
}
More...

VUE练习1 - 添加页面

1 Vue 的目录结构

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
src/         主开发目录,要开发的客户端代码文件(单文件组件,样式、工具函数等等)全部在这个目录下
static/ 静态资源目录,项目中的静态资源(css,js,图片等文件)放在这个文件夹
dist/ 项目打包发布文件夹,目前没有这个文件夹,最后要上线单文件项目文件都在这个文件夹中
后面使用npm build 打包项目,让项目中的vue组件经过编译变成js 代码以后,dist就出现了

node_modules/ node的包目录,项目运行的依赖包存储目录,
package.json和package-lock.json文件中会自动记录了这个目录下所有的包以及包的版本信息,
如果node_modules没有,但是有package.json,则可以在终端下,通过npm install进行恢复。

config/ 配置目录,是环境配置目录与项目无关。
build/ 项目打包时依赖的目录
src/router/ 路由,是我们创建项目的时候,如果选择安装vue-router,就自动会生成这个目录。
src/assets/ 静态资源存储目录,与static目录作用类似。
src/components/ 组件存储目录,就是浏览器中用户看到的页面的一部分内容。
src/views/ 组件存储目录,就是浏览器中用户看到的页面内容,views往往会加载并包含components中的组件进来

2 执行流程图

graph TD
A(index.html 全局唯一入口)-->B(main.js VUE项目初始化入口)
B-->C(App.vue 根组件/路由)
C-->D1(首页页面组件)
C-->D2(登录页面组件)
C-->D3(商品页面组件)
D1-->E1(头部子组件)
D2-->E1
D3-->E1
D2-->E2(脚部子组件)
D1-->E2
D3-->E2
F(router/index.js 配置路由)-->C
More...

Javascript 箭头函数

Javascript 箭头函数

1
2
var arr = [11,22,33,44]
var res = arr.filter((item,index)=> item>30)

其等价形式为:

1
2
3
4
var arr = [11,22,33,44]
var res = arr.filter(function(item,index){
return item>30
})

在 vue 中常常可以看到箭头函数的使用:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<script>
// give each todo a unique id
let id = 0

export default {
data() {
return {
newTodo: '',
todos: [
{ id: id++, text: 'Learn HTML' },
{ id: id++, text: 'Learn JavaScript' },
{ id: id++, text: 'Learn Vue' }
]
}
},
methods: {
addTodo() {
// ...
this.todos.push({id:id++,text:this.newTodo})
this.newTodo = ''
},
removeTodo(todo) {
// ...
this.todos = this.todos.filter((t)=>t!=todo)
}
}
}
</script>

<template>
<form @submit.prevent="addTodo">
<input v-model="newTodo">
<button>Add Todo</button>
</form>
<ul>
<li v-for="todo in todos" :key="todo.id">
{{ todo.text }}
<button @click="removeTodo(todo)">X</button>
</li>
</ul>
</template>

其中的 this.todos = this.todos.filter ((t)=>t!=todo) 就是箭头函数。 可以实现列表的删除效果。
原理就是把不等于todo的元素筛选出来,也就是去除了todo。

请我喝杯咖啡吧~

支付宝
微信