标签归档:debian

debian下sudo的配置和使用

最近想使用PHP输入 命令行,控制服务器。立马就想到了使用 sudo来配置权限。
debian默认情况下已经装了sudo,如果要编辑sudo权限需要用root来操作,或者 输入命令
#sudo visudo

这里 假设要用PHP脚本控制服务器关机和重启,apache,php都是使用apt包安装的。这种情况下 php执行命令的用户默认会是 www-data ,所以编辑权限可以直接在最后一行添加

www-data ALL=NOPASSWD:/sbin/shutdown,/sbin/reboot (如果多个命令用逗号隔开)
(www-data)第一个是允许使用用户,如果前面加 % 则是允许的用户组。
(ALL) 允许登录的所有主机,包括本地和远程
(NOPASSWD) 这里是不用输入密码
(/sbin/shutdown,/sbin/reboot) 这里就是允许的命令了,如果是所有命令的话 直接 ALL 就行了

visudo跟vi又不太一样,退出的话 可以使用 Ctrl+x ,然后会提示 是否保存 输入 y,然后回车。。。

就可以使用 PHP执行这些命令了。。。

<?php
    system("/usr/bin/sudo reboot");  //重启
?>

最简安装debian后,sudo添加自动补全功能

用Linux的用户常常喜欢输入命令的前几个字符后按按TAB键自动补全,这样就不用输入所有字母了。

不过常常要通过加sudo取得管理员权限操作,这样就不能 TAB键补齐了。
这里有个小技巧,可以在sudo后照常OK!
方法就是:
在~/.bashrc中加入一行:complete -c sudo

debian隐藏Apache和PHP版本信息

隐藏 Apache 版本

apache 的 httpd.conf 有两个配置可以控制是否显示服务器信息给用户。
ServerTokens
ServerSignature
默认条件下会把apache版本 系统 模块都显示出来 (HTTP 返回头)
设置为:
ServerTokens ProductOnly
ServerSignature Off
就隐藏Apache的Apache Version信息。
ServerTokens Prod
服务器会发送(比如): Server: Apache
ServerTokens Major
服务器会发送(比如): Server: Apache/2
ServerTokens Minor
服务器会发送(比如): Server: Apache/2.0
ServerTokens Min
服务器会发送(比如): Server: Apache/2.0.41
ServerTokens OS
服务器会发送(比如): Server: Apache/2.0.41 (Unix)
ServerTokens Full (或未指定)
服务器会发送(比如): Server: Apache/2.0.41 (Unix) PHP/4.2.2 MyMod/1.2
如果是debian系统,则是在 /etc/apache2/conf.d/security 里面进行设置。。。
隐藏 PHP 版本
php.ini
expose_php On
改成
expose_php Off
重启apache后,php版本在http头中隐藏了。

解决 debian TAB 键不能自动补全命令的原因

一般情况,命令行输入 sudo apt-get ins 按 tab ,它后面会自动补全为 install 如果右面写了包的名的一部分,按 tab 它也会自动完成或列出候选的,这次装了个 debian 5 突然不好使了

首先确认是否安装了 自动补全的插件,输入

apt-get install bash-completion

问了一圈都不知道,后来还是在老外的 blog 上找到答案:

即 在 .bash_profile 里加

if [ -f /etc/bash_completion ]; then
. /etc/bash_completion
fi

就 ok 了

链接:http://gumelta.com/add-bash-completion-in-debian.php

完整 copy 下来吧:

Add Bash Completion In Debian

ash completion is a useful tool for completion of file paths, commands etc. By default it is enabled on Ubuntu but not on Debian. With two simple steps it can also be enabled on Debian.

1. Install bash-completion

First of all we need the install the according package:

apt-get install bash-completion

2. Add it to the bash profile

Either edit the ~/.bash_profile file to enable it only for a given user or edit /etc/profile to add it system-wide. Add the following code:
if [ -f /etc/bash_completion ]; then
. /etc/bash_completion
fi
3. Try it

In order for it to work you have to log out and relogin and then you can make use of bash completion the usual way. E.g. issue:
apt-g

and then press the TAB key once and the command will be completed to apt-get. Or issue this:
apt

and then press TAB key twice. You can also try with
apt-get install apa

and then press TAB key once to complete as far as possible and a second time to list all options.

转自:http://hi.baidu.com/liheng_2009/

Debian Linux下,locale语言环境设置

这几天公司准备新添服务器,操作系统沿用以前的系统 Debian Linux。安装系统的时候为了省事,选择了中文,结果SSH连上去中文就是乱码,还是要改回英文才行。网上搜了大半天终于找到适合  Debian Linux 修改语言环境的方法。。。

原来locale文件在 /etc/default/locale

# vi /etc/default/locale

注释掉下面两行

LANG=”zh_CN.UTF-8″
LANGUAGE=”zh_CN:zh”

 

下面是百度的多种方法

Linux 切换 locale 语言设置的四种方法(总有一种方法可以解决):

1) 从CDE登录屏幕上修改locale
选择 options -> languages -> choose the new locale
2) 临时设置locale(shell相关的)
ksh : LANG=<locale>
sh : LANG=<locale>
export LANG
csh : setenv LANG <locale>
bash: export LANG=en_US(zh.GBK)
3) vi /etc/default/init
add
LANG=<locale>
LC_ALL=<locale>
reboot。
4) .cshrc/.profile/.bashrc: 设置$LANG