Press "Enter" to skip to content

月度归档: 2011 年 11 月

c 字符串小写转大写

常用的C小写字母转大写程序

#include <stdio.h>
int main(void)
    {
          int i=0;
          char string[100];
          strcpy(string,"abcdefghijklmnopqrstuvwxyz");
     while (string[i]!='\0'){ //将小写转化成大写
                  if (islower(string[i]))
                      string[i]=toupper(string[i]);
           i++;
       }
       printf("%s\n",string);
       return 0;
    }  

输出:
ABCDEFGHIJKLMNOPQRSTUVWXYZ
Leave a Comment

C语言写文件

C语言写文件操作,先记录一下。

#include<stdio.h>
#define set_s (x,y) {strcoy(s[x].name,y);s[x].size=strlen(y);}
#define nmemb 3
struct test
{
    char name[20];
    int size;
}
s[nmemb];
main()
{
    FILE * stream;
    set_s(0,"Linux!");
    set_s(1,"FreeBSD!");
    set_s(2,"Windows2000.");
    stream=fopen("/tmp/fwrite","w");
    fwrite(s,sizeof(struct test),nmemb,stream);
    fclose(stream);
}
Leave a Comment

整理了一份VPS 安全设置

修改 SSH 默认端口

不要使用默认的 22 端口,这样很容易暴露 SSH 服务,也为暴力猜解用户名和密码留下了隐患。解决方法:将 /etc/ssh/sshd_config 中的 Port 改为其他端口。

禁止 root 帐号 SSH 登录

这样也是相当危险的,一般的做法是通过 SSH 配置文件,限制 root 帐号直接登录。
修改 /etc/ssh/sshd_config
将 PermitRootLogin 的值改为 no
这样,SSH 一律使用普通用户登录,在需要执行更高权限命令时,通过 sudo 命令,或者 su 成 root 再执行。

限制账号多重登陆

这样的做法,能让同一个账号,在同一时间内不能被多人同时登录。
实现方法:编辑 /etc/security/limits.conf
加入如下配置项即可:
* hard maxlogins 2

防 ping
# 禁止 ping
echo 1 > /proc/sys/net/ipv4/icmp_echo_ignore_all
# 允许 ping
echo 0 > /proc/sys/net/ipv4/icmp_echo_ignore_all

一、生成密钥对

可以使用命令行 ssh-keygen 生成(RSA/DSA 二选一):
# RSA
ssh-keygen -t rsa -b 2048 -C kiccleaf@163.com
# DSA
ssh-keygen -t dsa -C kiccleaf@163.com

当然也可以使用 putty 的 puttygen 工具生成。
SSH 登录需要 OpenSSH 格式的公钥,ssh-keygen 生成的 id_rsa.pub / id_dsa.pub 就是这种格式,如果是用 puttygen 生成,需要导出为 OpenSSH 格式。

二、添加服务端公钥
用将要使用密钥的用户登录 VPS。
cd
mkdir -p .ssh
chmod 755 .ssh

# RSA
cat id_rsa.pub >> .ssh/authorized_keys
# RSA
cat id_dsa.pub >> .ssh/authorized_keys2

chmod 644 .ssh/authorized_keys

三、配置 SSH 服务端

编辑 /etc/ssh/sshd_config,修改以下几个参数,禁止 root 账号 和 使用密码 直接登录:

PermitRootLogin no
PasswordAuthentication no

重启 SSH 服务:
/etc/init.d/sshd restart

四、配置 SSH 客户端

SecureCRT 可以直接使用 OpenSSH 格式的密钥,putty 则需要使用 puttygen 导入 id_rsa / id_dsa 再保存为 .ppk 格式的私钥。

Leave a Comment

php随机生成字符串

分享一下PHP随机生成字符串,以便以后使用时拿出来。

function random($length)
{
$hash = '';
$chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_abcdefghijklmnopqrstuvwxyz';
$max = strlen($chars) - 1;
mt_srand((double)microtime() * 1000000);
$chr_len = rand(3,$length);
for($i = 0; $i &lt; $chr_len; $i++)
{
$hash .= $chars[mt_rand(0, $max)];
}
 return $hash;
}
Leave a Comment

Win2008服务器IIS7.0-7.5在指定目录下创建虚拟目录[原创]

添加一个指定目录test目录下upload虚拟目录。适合Windows2008及Windows7系统,此操作不适合Windows2003系统中的IIS6.0。

#引用
using Microsoft.Web.Administration;

#代码
ServerManager sm = new ServerManager();
Site site = sm.Sites["www.kiccleaf.com"];//站点的名称
if (site != null)
{
   Microsoft.Web.Administration.Application application = site.Applications["/"];
   if (application != null)
    {
      VirtualDirectory reportDir = application.VirtualDirectories.Add("/images/upload", @"C:\TestWebSite\upload");
    }
    sm.CommitChanges();
 }
Leave a Comment