海运的博客

Centos服务器安全配置SSH使用Google Authenticator二次验证

发布时间:August 30, 2012 // 分类:网络安全 // 2 Comments

CentOS安装所需组件:

yum -y install mercurial pam-devel

安装Google Authenticator:

#https://www.haiyun.me
wget --no-check-certificate https://google-authenticator.googlecode.com/files/libpam-google-authenticator-1.0-source.tar.bz2
tar jxvf libpam-google-authenticator-1.0-source.tar.bz2 
cd libpam-google-authenticator-1.0
make
make install

SSH登录时调用google-authenticator模块,编辑:

/etc/pam.d/sshd

第一行添加:

auth       required     pam_google_authenticator.so

修改SSH配置文件:

vim /etc/ssh/sshd_config

添加或修改以下内容:

ChallengeResponseAuthentication yes
UsePAM yes

重启SSH:

/etc/init.d/sshd restart

生成google-authenticator配置,运行:

google-authenticator 
Do you want authentication tokens to be time-based (y/n) y
https://www.google.com/chart?chs=200x200&chld=M|0&cht=qr&chl=otpauth://totp/root@node1.www.haiyun.me%3Fsecret%3DABEXG5K6CVB56BXY
#此网址为生成的二维码,客户端扫描
Your new secret key is: www.haiyun.me
Your verification code is 582849
Your emergency scratch codes are:
  30776626
  14200155
  80795568
  23936997
  21919909
#上面几行数字为应急码
Do you want me to update your "/root/.google_authenticator" file (y/n) y
#更新配置文件
Do you want to disallow multiple uses of the same authentication
token? This restricts you to one login about every 30s, but it increases
your chances to notice or even prevent man-in-the-middle attacks (y/n) y
#禁止一个口令多用
By default, tokens are good for 30 seconds and in order to compensate for
possible time-skew between the client and the server, we allow an extra
token before and after the current time. If you experience problems with poor
time synchronization, you can increase the window from its default
size of 1:30min to about 4min. Do you want to do so (y/n) n
#客户端与服务器时间误差
If the computer that you are logging into isn't hardened against brute-force
login attempts, you can enable rate-limiting for the authentication module.
By default, this limits attackers to no more than 3 login attempts every 30s.
Do you want to enable rate-limiting (y/n) y
#次数限制

Android安装google-authenticator客户端,扫描添加上方网址的二维码,以后在登录服务器时输入账号密码的同时还需输入google-authenticator即时生成的验证码才能登录。

ssh www.haiyun.me
Verification code: 
Password: 

SSH管理服务器必备多窗口工具Screen使用

发布时间:August 19, 2012 // 分类:常用软件 // No Comments

在使用SSH管理服务器最怕的就是突然断开了,这样会导致当前运行的任务终止甚至造成数据丢失,使用Screen可避免此类事情的发生。
CentOS一般都自带Screen,安装也很方便:

yum install screen

Screen常用参数:

#https://www.haiyun.me
-ls #列出当前screen会话
-d #将指定的screen会话离线
-r #恢复指定的screen会话
-U #使用UTF-8编码
-R #先试图恢复离线的作业,若无离线作业则建立新的screen会话
-x #恢复之前离线的会话,使用-R多会话下适用
-S name #新建指定名称会话
-dmS name #以分离模式新建会话
-wipe #列出当前screen会话,并清除不正常的会话

在Screen窗口下常用快捷命令:

C-a c #新建会话
C-a n #下个会话
C-a p #前个会话
C-a 0-9 #切换指定会话
Ctrl+a [Space] #顺序切换会话
C-a C-a #两个常用会话间切换
C-a x #锁住当前会话
C-a d #分离当前会话
C-a z #后台执行当前会话
C-a w #列出当前所有会话
C-a t #显示系统时间和负载
C-a K #终止当前会话

应用示例:
进入Screen会话:

screen

分离当前会话:

C-a d
#即按Ctrl不松开接着安a、d键

分离后不影响Screen会话中的任务,查看分离的会话:

screen -ls

恢复分离的Screen会话:

screen -r <id>

Windows下使用Xshell连接可参考:Xsehll配合Screen再也不怕SSH会话意外断开

Centos安装X window配置ssh X转发

发布时间:July 14, 2012 // 分类:Linux基础 // No Comments

先安装X Window环境:

#https://www.haiyun.me
yum groupinstall "X Window System"

配置SSH开启X转发:

cat /etc/ssh/sshd_config
X11Forwarding yes

SSH客户端开启X转发,Xshell设置如下:
xshell开启X转发.png
安装X-Server for Windows,推荐免费开源Xming

SSH常用命令妙用

发布时间:July 2, 2012 // 分类:常用软件,Linux基础 // No Comments

之前有介绍Putty工具Plink应用,Linux下ssh同样可实现很多妙用。
1.动态socks5端口转发,可用于代**理上网

ssh -NfD 0.0.0.0:7070 root@haiyun.me
-D #动态转发端口

2.转发本地端口到远程服务器:

#转发本机8080端口到google.com 80端口
ssh -N -f -L <0.0.0.0>:8080:google.com:80 root@haiyun.me
-N #仅转发端口,不执行命令
-f #后台运行
-L #监听地址端口,-L [bind_address:]port:host:hostport

3.转发远程服务器端口到本地端口,远程服务器监听指定地址查看:https://www.haiyun.me/archives/1010.html

ssh -N -f -R 0.0.0.0:8080:localhost:80 root@haiyun.me
#转发远程服务器8080端口到本地80端口

4.登录服务器并执行文本内的命令:

ssh user@server "`cat test.txt`"

5.测试两台服务器的带宽:

yes | pv | ssh user@server "cat > /dev/null"

6.登录到远程服务器screen窗口,如断开、连接不受影响。

ssh -t user@server /usr/bin/screen -xRR

此内容被密码保护

发布时间:July 2, 2012 // 分类:OpenWrt // No Comments

请输入密码访问

分类
最新文章
最近回复
  • 海运: 恩山有很多。
  • swsend: 大佬可以分享一下固件吗,谢谢。
  • Jimmy: 方法一 nghtp3步骤需要改成如下才能编译成功: git clone https://git...
  • 海运: 地址格式和udpxy一样,udpxy和msd_lite能用这个就能用。
  • 1: 怎么用 编译后的程序在家里路由器内任意一台设备上运行就可以吗?比如笔记本电脑 m参数是笔记本的...
  • 孤狼: ups_status_set: seems that UPS [BK650M2-CH] is ...
  • 孤狼: 擦。。。。apcupsd会失联 nut在冲到到100的时候会ONBATT进入关机状态,我想想办...
  • 海运: 网络,找到相应的url编辑重发请求,firefox有此功能,其它未知。
  • knetxp: 用浏览器F12网络拦截或监听后编辑重发请求,修改url中的set为set_super,将POS...
  • Albert: 啊啊啊啊啊啊啊啊啊 我太激动了,终于好了英文区搜索了半天,翻遍了 pve 论坛没找到好方法,博...