---
title: "Linux命令随记（CentOS）"
author: "Andy_Dou"
date: "2014-07-30T08:52:48Z"
tags: []
categories: ["操作系统"]
slug: "linux-centos"
draft: false
lastmod: "2017-01-03T10:02:55Z"
id: 2098052
url: "https://ideabean.iteye.com/blog/2098052"
---

将查询到的文件删除：

```
# find ./ -name ".DS_Store" | xargs rm -rf
```

 

分配权限：

```
# chown -R www(用户):www(用户组) /alidata/www/aliyun-test.com/
```

 

启动目录：

```
# cd /etc/init.d
```

 

设置环境变量：

```
--系统级别
# vi /etc/profile

--用户级
# cd ~
# vi .bash_profile
```

 

 添加系统用户：

```
# passwd 用户名（更改用户密码）
# useradd 用户名 (添加用户)
```

 

重置ROOT密码：

```
1.在grub选项菜单按e进入编辑模式

2.编辑kernel那行 /init 1 (或/single)

3.按B重启

4.进入后执行下列命令

　　root@#passwd root (配置root的密码)

　　Enter new unix password:输入新的密码

　　root@#init 6
```

 

防止进行root密码重置的方法：

```
1.grub有一个配置文件，在/etc目录 编辑grub.conf

2.内容如下

# grub.conf generated by anaconda
#
# Note that you do not have to rerun grub after making changes to this file
# NOTICE:  You have a /boot partition.  This means that
#          all kernel and initrd paths are relative to /boot/, eg.
#          root (hd0,0)
#          kernel /vmlinuz-version ro root=/dev/xvda3
#          initrd /initrd-[generic-]version.img
#boot=/dev/xvda
default=0
timeout=5
splashimage=(hd0,0)/grub/splash.xpm.gz
hiddenmenu
title CentOS (2.6.32-431.el6.x86_64)
root (hd0,0)
kernel /vmlinuz-2.6.32-431.el6.x86_64 ro root=UUID=bff89618-99a8-427e-968c-e08fcb8041d9 rd_NO_LUKS rd_NO_MD console=hvc0  KEYTABLE=us crashkernel=auto LANG=zh_CN.UTF-8 rd_NO_LVM rd_NO_DM rhgb quiet
initrd /initramfs-2.6.32-431.el6.x86_64.img

共有两个地方可以添加密码。

3.第一处是“timeout=10”的下面，在这里加上“password=123456”（123456是自己的密码）。保存，退出，重启。我们可以看到，在grub的界面上已经不可以按“e”进行修改了。想修改必须按“p”输入密码后进行修改。

4.第二处是“initrd /initrd-2.4.20-8.img”的下面。在这里加上“password=123456”（123456是自己的密码）。保存，退出，重启。我们可以看到，linux启动前（过了grub界面）又多了一个密码。值得注意的是：这个密码是可以防止单用户模式进入的。也就是说，即使我们通过编辑grub启动单用户模式，还是要输入这个密码的。
```