当前位置:  操作系统/服务器>linux
本页文章导读:
    ▪ssh在linux安全中所起的作用有哪些      来看具体的操作实例。   代码示例: [root@xxx ~]# ssh 192.168.1.1 The authenticity of host '192.168.1.1 (192.168.1.1)'can't be established. RSA key fingerprint is83:8f:76:3a:42:31:b0:95:49:72:8a:a7:1c:39:08:e6. Are you sure you want t.........
    ▪linux安全配置之权限篇      1,权限 ugo ( r - w - x ) 当一个用户访问一个文件的时候 1、如果当前用户的UID与文件owner的UID匹配,那么就遵守第一个三位组的权限,如果不匹配那么看GID 2、如果当前用户的GID与文件group的GI.........
    ▪iptables防火墙之limit限制方法分享      本节介绍iptables --limit --limit-burst的用法。 它们主要用于: 1、限制特定包传入速度 2、限制特定端口传入频率 3、使用--limit限制ping的一个例子 4、用户自定义使用链 5、防范SYN-Flood碎片攻击 .........

[1]ssh在linux安全中所起的作用有哪些
    来源: 互联网  发布时间: 2013-12-24

来看具体的操作实例。
 

代码示例:
[root@xxx ~]# ssh 192.168.1.1
The authenticity of host '192.168.1.1 (192.168.1.1)'can't be established.
RSA key fingerprint is83:8f:76:3a:42:31:b0:95:49:72:8a:a7:1c:39:08:e6.
Are you sure you want to continue connecting (yes/no)?yes
Warning: Permanently added '192.168.1.1' (RSA) to thelist of known hosts.
root@192.168.1.1's password:
Last login: Sun Aug 28 22:05:29 2011
[root@xxx ~]#
 
[root@xxx ~]# ssh user1@192.168.1.1
user1@192.168.1.1's password:
Last login: Fri Jun 17 01:11:57 2011 from 192.168.1.254
[user1@xxx ~]$
 

安全 Shell (SSH)允许使用私钥-公钥进行身份验证。私钥自己妥善保管,公钥告知任何人。
拥有公钥的 SSH 服务器可以发布仅由私钥的系统才可解答的问题。因此可以根据所持有的密钥进行验证。这样在每次访问系统时不必键入密码,但安全性仍能得到保证。
 
可以使用ssh-keygen 命令生成密钥。
 

代码示例:
[root@xxx ~]# ssh-keygen -t rsa
Generating public/private rsa key pair.
Enterfile in which to save the key (/root/.ssh/id_rsa):
Enter passphrase (empty for no passphrase): 123456
Enter same passphrase again: 123456
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:
0c:cf:fc:b0:e3:00:5a:dd:6d:7b:1d:af:9c:8b:05:86root@xxx.localdomain
 

在生成密钥期间,将提供用与指定密码的选项。必须提供密码才能访问私钥。
通过此方法,即使密钥被盗,也很难使用密钥。这样在攻击者破解并使用私钥前,可以生成新的密钥并删除所有涉及旧密钥的内容。
 
生成 SSH 密钥后,密钥将默认存储在家目录的 .ssh/ 目录中:
 

代码示例:
[root@xxx ~]# ls ~/.ssh/
id_rsa id_rsa.pub  known_hosts

可以使用ssh-copy-id 将自己的公钥复制到目标系统
 

[root@xxx ~]# ssh-copy-id -i ~/.ssh/id_rsa.pubuser1@192.168.1.1
user1@192.168.1.1's password:
Now try logging into the machine, with "ssh'user1@192.168.1.1'", and check in:
.ssh/authorized_key
[root@xxx ~]# ssh user1@192.168.1.1
Last login: Tue Sep 6 10:50:26 2011 from 192.168.1.254
[user1@xxx ~]$
 

 
SSH 端口转发

SSH 会自动加密和解密所有 SSH 客户端与服务端之间的网络数据。但是,SSH 还同时提供了一个非常有用的功能,这就是端口转发。它能够将其他 TCP 端口的网络数据通过 SSH 链
接来转发,并且自动提供了相应的加密及解密服务。这一过程有时也被叫做“隧道”(tunneling),这是因为 SSH 为其他 TCP 链接提供了一个安全的通道来进行传输而得名。
例如,Telnet,SMTP,LDAP 这些 TCP 应用均能够从中得益,避免了用户名,密码以及隐私信息的明文传输。而与此同时,如果您工作环境中的防火墙限制了一些网络端口的使用,但
是允许 SSH 的连接,那么也是能够通过将 TCP 端口转发来使用 SSH 进行通讯。

SSH 端口转发提供两大功能:
1,加密 SSHClient 端至 SSHServer 端之间的通讯数据。
2,突破防火墙的限制完成一些之前无法建立的 TCP 连接。
 

Client<------------>SSHServer<-------------->WEB Server
SSH Server:1.1.1.254/24 172.16.1.254/24
[root@xxx ~]# ssh -g -L 80:172.16.1.1:80172.16.1.254
ssh -L <local port>:<remote host>:<remoteport> <SSH servername>
 

没有指定-g 参数的情况下,80 这个端口只接受本机的连接,指定-g 参数 SSH Server 的 80 端口可以接受其他主机的连接WEB Server:172.16.1.1/24。
 

代码示例:

[root@xxx ~]# cat /var/www/html/index.html
html test

Client:1.1.1.1/24
[root@xxx ~]# elinks --dump http://1.1.1.254
html test


    
[2]linux安全配置之权限篇
    来源: 互联网  发布时间: 2013-12-24

1,权限 ugo ( r - w - x )
当一个用户访问一个文件的时候
1、如果当前用户的UID与文件owner的UID匹配,那么就遵守第一个三位组的权限,如果不匹配那么看GID
2、如果当前用户的GID与文件group的GID匹配,那么就遵守第二个三位组的权限
3、如果当前用户的UID与GID和文件的owner与group都不匹配,那么就看第三个三位组other的权限。
了解到匹配权限的过程之后,接下来学习三位组中rwx的具体含义。
 

文件 目录
r 浏览(cat) 浏览(ls)
w 编辑(vim) 创建/删除(touch,rm)
x 执行(script) 改变(cd)
- 无 无

2,默认权限与umask
默认情况下,管理员的umask 022,普通用户的umask 002。
下面以文件默认权限是666,umask是033,来介绍一个文件的权限。
1).666的权限是rw- rw- rw-,换算成2进制 110 110 110
2).umask033 权限是 --- -wx-wx ,换算成2进制 000 011 011
3).umask 2进制取反 000 011 011 -------->111 100 100
4).umask 取反后的2进制和默认权限做与运算
 

umask 111 100 100
默认权限 110 110 110
--------------------------------------
110 100 100
rw- r-- r--

5).得到最终的权限 644
 
3.SUID SGID Sticky
可执行文件SUID SGID
执行可执行文件的时候,不以执行者的身份去运行,而是以文件所属人(组)的身份去执行目录。
SGID Sticky
SGID:当一个A目录具有SGID的时候,在这个目录下新建的文件文件夹默认所属组会是A目录的所属组。
Sticky:当A目录具有Sticky位的时候,在A目录下的文件只有文件的所属人才能够删除文件,其他人哪怕对A目录有写的权限也不能删。
 
设置suid和SGID
给文件加SUID和SGID的命令如下:
 

chmodu+s filename 设置SUID位
chmodu-s filename 去掉SUID设置
chmodg+s filename 设置SGID位
chmodg-s filename 去掉SGID设置

注意:
大部分 UNIX 类系统都会忽略掉SHELL脚本的 suid ,只有二进制可执行程序的 suid 有效 。所以直接给脚本文件设置 suid 是达不到预期效果的。
例如,有shell脚本 apk.sh,即使执行命令 #chmod 4755 apk.sh ,系统也会忽略该脚本的SUID位。
所以如果确实需要给脚本文件设 suid,常见的做法是用 C 写一个封装程序,在这个程序里调用脚本。
这样,给封装程序(二进制可执行程序)设上 suid(chmod 4755 a.out) 即可达到给脚本文件设suid的效果。

4,ext3文件系统属性
chattr lsattr
 
lsattr   [-aR]
参数说明:
-a  :将隐藏文件的属性也显示出来
-R  :连同子目录的数据一并显示出来
 
chattr  [+-=] [ASacdistu]  [文件或目录名称]
A:当设定了属性A,这个文件(或目录)的存取时间atime(access)将不可被修改,可避免诸如笔记本电脑容易产生磁盘I/O错误的情况;
S:这个功能有点类似sync,是将数据同步写入磁盘中,可以有效避免数据流失;
a:设定a后,这个文件将只能增加数据而不能删除,只有root才能设定这个属性;
c:设定这个属性后,将会自动将此文件压缩,在读取时自动解压缩。但是在存储的时候,会现进行压缩在存储(对于大文件很有用);
d:当dump(备份)程序执行时,设定d属性将可使该文件(或目录)具有dump功效;
i:这个参数可以让一个文件”不能被删除、更名、设定链接,也无法写入数据,对于系统安全有很大的助益
j:当使用ext3文件系统格式时,设定j属性将使文件在写入时先记录在日志中,
但是当filesystem设定参数为data=journalled时,由于已经设定了日志,所以这个属性无效
s:当文件设定了s参数时,它会被完全移出这个硬盘空间
u:与s相反,当使用u配置文件时,数据内容其实还可以存在于磁盘中,可以用来取消删除。
 
测试效果:
1》
 

代码示例:
[root@xxx tmp]#ls
file1
[root@xxx tmp]#stat file1
  File: “file1”
  Size: 15              Blocks: 16         IO Block: 4096   一般文件
Device:fd00h/64768d    Inode: 163203      Links: 1
Access:(0644/-rw-r--r--)  Uid: (    0/   root)   Gid: (    0/   root)
Access: 2012-12-1015:18:02.000000000 +0800
Modify: 2012-12-1015:19:28.000000000 +0800
Change: 2012-12-1015:19:28.000000000 +0800
[root@xxx tmp]#lsattr file1
-------A----- file1

注意:Modify和Change的时间都比Access time晚,说明access time 不做更新,但是redhat 6.2 access time更新不及时。
 
2》
 

代码示例:
[root@xxx tmp]#cat file1
diafdsafsafsaf
afdsa
afdsa
[root@xxx tmp]#echo "afdsa">file1
-bash: file1: 不允许的操作
[root@xxx tmp]#echo "afdsa">>file1
[root@xxx tmp]#cat file1         
diafdsafsafsaf
afdsa
afdsa
afdsa
[root@xxx tmp]#rm -fr file1
rm: 无法删除 “file1”: 不允许的操作

5.文件系统的访问控制列表
 

代码示例:
setfacl -m (--modify)u:user:permission file | directory 对文件或者文件夹设置facl权限
setfacl -m (--modify)u:group:permission file | directory 对组设置facl权限
setfacl -m (--modify) d:u:user:permissiondirectory 任何人新建的文件都会变成文件夹所有人
getfacl  file  查看file文件的权限
setfacl -x u:soft  test 去掉单个用户的权限
setfacl -b test  删除test目录的所以acl权限

测试:
1》
 

代码示例:
[root@xxx tmp]# mkdir dir1
[root@xxx tmp]# chmod 700 dir1/
[root@xxx tmp]# setfacl -mu:test:rwx dir1
[root@xxx tmp]# su test
[test@xxx tmp]$ cd dir1/
[root@xxx tmp]# setfacl -b dir1/
[root@xxx tmp]# su test
[test@xxx tmp]$ cd dir1/
bash: cd: dir1/: 权限不够

linux操作系统跟外部设备(如磁盘、光盘等)的通信都是通过设备文件进行的,应用程序可以打开、关闭、读写这些设备文件,从而对设备进行读写,这种操作就像读写普通的文件一样easy。
linux为不同种类的设备文件提供了相同的接口,比如read(),write(),open(),close()。
 
所以在系统与设备通信之前,系统首先要建立一个设备文件,这个设备文件存放在/dev目录下。
其实系统默认情况下就已经生成了很多设备文件,但有时候我们需要自己手动新建一些设备文件,此时就会用到像mkdir, mknod这样的命令。
mknod 的标准形式为:
mknod DEVNAME {b | c}  MAJOR MINOR
 
1,DEVNAME是要创建的设备文件名,如果想将设备文件放在一个特定的文件夹下,就需要先用mkdir在dev目录下新建一个目录;
 
2, b和c 分别表示块设备和字符设备:
b表示系统从块设备中读取数据的时候,直接从内存的buffer中读取数据,而不经过磁盘;
c表示字符设备文件与设备传送数据的时候是以字符的形式传送,一次传送一个字符,比如打印机、终端都是以字符的形式传送数据;
 
3,MAJOR和MINOR分别表示主设备号和次设备号:
为了管理设备,系统为每个设备分配一个编号,一个设备号由主设备号和次设备号组成。主设备号标示某一种类的设备,次设备号用来区分同一类型的设备。linux操作系统中为设备文件编号分配了32位无符号整数,其中前12位是主设备号,后20位为次设备号,所以在向系统申请设备文件时主设备号不好超过4095,次设备号不好超过2^20 -1。

用mknod命令来申请设备文件。     
 

代码示例:
mkdir -p /dev/cobing
mknod /dev/cobing/mydev1 c 128 512

查看系统设备的主设备号,可以参考/usr/share/doc/kernel-doc-2.6.18/Documentation/devices.txt文件中的说明。
 
文件系统的挂载选项
 

代码示例:
noexec  exec
[root@xxx ~]# mount /dev/hdb1  /test/
[root@xxx ~]# echo"hello" > /test/file1
[root@xxx ~]# cp /bin/cat /test/
[root@xxx ~]# cd /test/
[root@xxx test]# ./cat file1
hello
[root@xxx test]# mount -oremount,noexec /test/
[root@xxx test]# ./cat file1
bash: ./cat: Permission denied
ro        rw
[root@xxx test]# mount -oremount,ro /test/
[root@xxx test]# echo"abc" >> /test/file1
bash: /test/file1: Read-only filesystem
nosuid   suid
[root@xxx test]# mount /dev/hdb1/test/
[root@xxx test]# ls
cat cdrom  file1  lost+found
[root@xxx test]# chmod 640 file1
[root@xxx test]# ls -l file1
-rw-r----- 1 root root 6 Mar  3 16:04 file1
[root@xxx test]# chmod u+s cat
[root@xxx test]# su - user1
[user1@xxx ~]$ cd /test/
[user1@xxx test]$ ./cat file1
hello
[root@xxx test]# mount -oremount,nosuid /test/
[root@xxx test]# su - user1
[user1@xxx ~]$ cd /test/
[user1@xxx test]$ ./cat file1
./cat: file1: Permission denied
nodev   dev
[root@xxx test]# ls -l /dev/cdrom
lrwxrwxrwx 1 root root 3 Mar  3 14:47 /dev/cdrom -> hdd
[root@xxx test]# ls -l /dev/hdd
brw-rw---- 1 root disk 22, 64Mar  3 14:47 /dev/hdd
[root@xxx test]# mknod cdrom b 2264
[root@xxx test]# mount cdrom /mnt/
mount: block device cdrom iswrite-protected, mounting read-only
[root@xxx test]# umount /mnt/
[root@xxx test]# mount -oremount,nodev /test/
[root@xxx test]# ls -l cdrom
brw-r--r-- 1 root root 22, 64Mar  3 16:13 cdrom
[root@xxx test]# mount cdrom /mnt/
mount: block device cdrom iswrite-protected, mounting read-only
mount: cannot mount block devicecdrom read-only
[root@xxx test]# ls /mnt/
noauto  auto
[root@xxx ~]# vim /etc/fstab
/dev/hdb1  /test  ext3  noauto
[root@xxx ~]# mount -a
noatime atime
Update inode access time foreach  access.  This is  the default.
async    sync

    
[3]iptables防火墙之limit限制方法分享
    来源: 互联网  发布时间: 2013-12-24

本节介绍iptables --limit --limit-burst的用法。

它们主要用于:
1、限制特定包传入速度
2、限制特定端口传入频率
3、使用--limit限制ping的一个例子
4、用户自定义使用链
5、防范SYN-Flood碎片攻击

下面分解开进行详细介绍。

1、限制特定包传入速度
参数 -m limit --limit
范例:
 

代码示例:
iptables -A INPUT -m limit --limit 3/hour

说明 用来比对某段时间内封包的平均流量,上面的例子是用来比对:每小时平均流量是否超过一次 3 个封包。 除了每小时平均
次外,也可以每秒钟、每分钟或每天平均一次,默认值为每小时平均一次,参数如后: /second、 /minute、/day。 除了进行封
数量的比对外,设定这个参数也会在条件达成时,暂停封包的比对动作,以避免因骇客使用洪水攻击法,导致服务被阻断。

2、限制特定包瞬间传入的峰值
参数 --limit-burst
范例:
 

代码示例:
iptables -A INPUT -m limit --limit-burst 5

说明 用来比对瞬间大量封包的数量,上面的例子是用来比对一次同时涌入的封包是否超过 5 个(这是默认值),超过此上限的封
将被直接丢弃。使用效果同上。

3、使用--limit限制ping的一个例子
限制同时响应的 ping (echo-request) 的连接数
限制每分只接受一個 icmp echo-request 封包(注意:当已接受1个icmp echo-request 封包后,
iptables将重新统计接受之后的一秒内接受的icmp echo-request 封包的个数,此刻为0个,所以它会继续接受icmp echo-request包,
出现的结果是你在1分钟时间内将看到很多:
 

Reply from 192.168.0.111: bytes=32 time<1ms TTL=64
Reply from 192.168.0.111: bytes=32 time<1ms TTL=64
Reply from 192.168.0.111: bytes=32 time<1ms TTL=64
Reply from 192.168.0.111: bytes=32 time<1ms TTL=64
Reply from 192.168.0.111: bytes=32 time<1ms TTL=64
Reply from 192.168.0.111: bytes=32 time<1ms TTL=64
Reply from 192.168.0.111: bytes=32 time<1ms TTL=64
Reply from 192.168.0.111: bytes=32 time<1ms TTL=64

响应结果,若同时开好几个ping窗口,任一时刻只有一个会有响应//--limit 1/m 所限制):
 

代码示例:

#iptables -A INPUT -p icmp --icmp-type echo-request -m limit --limit 1/m --limit-burst 1 -j ACCEPT
#iptables -A INPUT -p icmp --icmp-type echo-request -j DROP

--limit 1/s 表示每秒一次; 1/m 则为每分钟一次
--limit-burst 表示允许触发 limit 限制的最大次数 (预设 5)

4、用户自定义使用链
 

代码示例:
#iptables -N pinglimit
#iptables -A pinglimit -m limit --limit 1/m --limit-burst 1 -j ACCEPT
#iptables -A pinglimit -j DROP
#iptables -A INPUT -p icmp --icmp-type echo-request -j pinglimit

5、防范 SYN-Flood 碎片攻击
 

代码示例:
#iptables -N syn-flood
#iptables -A syn-flood -m limit --limit 100/s --limit-burst 150 -j RETURN
#iptables -A syn-flood -j DROP
#iptables -I INPUT -j syn-flood

您可能感兴趣的文章:
iptables 日志维护的方法分享
解析 iptables常用规则设置
linux下关闭iptables防火墙及selinux的方法
使用iptables屏蔽IP段的方法举例
配置 iptables 静态防火墙
iptables实现路由转发的例子
iptables防火墙配置一例
iptables配置实例详解
一个实用的iptables shell脚本
iptables实例收藏
linux iptables 开启关闭端口的方法
linux iptables入门教程

    
最新技术文章:
▪linux系统中的列出敏感用户的脚本代码
▪a10 config backup for aXAPI
▪一键备份gitolite服务器的Shell脚本
▪nagios 分发文件实现代码
▪阿里云云服务器Linux系统更新yum源Shell脚本
▪一个监控LINUX目录和文件变化的Shell脚本分享
▪Linux下实现SSH免密码登录和实现秘钥的管理、...
▪Shell正则表达式之grep、sed、awk实操笔记
▪3个备份系统文件并邮件发送的Shell脚本分享
▪CentOS 6.3下给PHP添加mssql扩展模块教程
▪监控网站是否可以正常打开的Shell脚本分享
▪shell脚本编程之if语句学习笔记
▪shell脚本编程之循环语句学习笔记
▪shell脚本编程之case语句学习笔记
▪Shell脚本实现的阳历转农历代码分享
▪Shell脚本实现复制文件到多台服务器的代码分...
▪Shell脚本实现批量下载网络图片代码分享
▪Shell脚本实现检测文件是否被修改过代码分享
▪Shell脚本数组用法小结
▪Shell脚本批量重命名文件后缀的3种实现
▪C语言实现的ls命令源码分享
▪Linux下查找后门程序 CentOS 查后门程序的shell脚...
▪Shell 函数参数
▪linux shell 自定义函数方法(定义、返回值、变...
▪Shell实现判断进程是否存在并重新启动脚本分...
▪Shell脚本break和continue命令简明教程
▪Shell脚本函数定义和函数参数
▪让代码整洁、过程清晰的BASH Shell编程技巧
▪shell常用重定向实例讲解
▪让代码整洁、过程清晰的BASH Shell编程技巧 iis7站长之家
 


站内导航:


特别声明:169IT网站部分信息来自互联网,如果侵犯您的权利,请及时告知,本站将立即删除!

©2012-2021,,E-mail:www_#163.com(请将#改为@)

浙ICP备11055608号-3