su switch user,用於切換用戶用
su常見命令參數
用法:su [選項]... [-] [用戶 [參數]... ] Change the effective user id and group id to that of USER. -, -l, --login make the shell a login shell -c, --command=COMMAND pass a single COMMAND to the shell with -c --session-command=COMMAND pass a single COMMAND to the shell with -c and do not create a new session -f, --fast pass -f to the shell (for csh or tcsh) -m, --preserve-environment do not reset environment variables -p same as -m -s, --shell=SHELL run SHELL if /etc/shells allows it --help 顯示此幫助信息並退出 --version 顯示版本信息並退出 單獨的"-"選項隱含了-l。如果不指定用戶,則假設其為root。
常用的命令展示
切換omd用戶
su – omd # root切換其他用戶不用輸密碼,普通用戶直接切換密碼需要知道那個用戶的登錄密碼
不切換用戶而直接執行命令:
omd用戶下:su - root -c "ifconfig" 需要輸入密碼
su 和 su - 的區別
su -: 會切換root用戶,也會把用戶變量也切換到root的環境變量
su : 只是會切換root用戶,但是當前的環境變量還是以前用戶的環境變量