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]#