linux常用工具su與su -

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

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章