2013年3月5日 星期二 3月10日整理筆記
一、創建用戶chenglong
[root@localhost ~]# useradd chenglong
[root@localhost ~]# vi /etc/shadow
二、對比
1、使用su
[root@localhost ~]# su chenglong
查看路徑
[chenglong@localhost root]$ pwd
/root
在根下,危險
[chenglong@localhost root]$ pwd
/root
創建目錄
[chenglong@localhost root]$ mkdir kuaicanche
mkdir: cannot create directory `kuaicanche': Permission denied #失敗
創建文件
[chenglong@localhost root]$ touch kuaicanche
touch: cannot touch `kuaicanche': Permission denied #失敗
[chenglong@localhost root]$
退出
[chenglong@localhost root]$ exit
exit
2、使用su -
[root@localhost ~]# su - chenglong
查看路徑
[chenglong@localhost ~]$ pwd
/home/chenglong
[chenglong@localhost ~]$
[chenglong@localhost ~]$ mkdir shiershengxiao
[chenglong@localhost ~]$ cd
[chenglong@localhost ~]$ exit
logout
[root@localhost ~]# find / -name shiershengxiao
/home/chenglong/shiershengxiao #成功
在用戶自己家目錄下,安全
三、執行一次指令
[root@localhost ~]# su - chenglong -c 'mkdir /tmp/test'
[root@localhost ~]# cd /tmp
[root@localhost tmp]# ls
gconfd-root mapping-root ssh-mLbITh2442 virtual-root.x90iG7
keyring-KvMtAQ orbit-root test
[root@localhost tmp]#