无线&移动互联网技术研发

换位思考·····
posts - 19, comments - 53, trackbacks - 0, articles - 283
  BlogJava :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理

登陆环境

Posted on 2009-11-29 11:59 Gavin.lee 阅读(236) 评论(0)  编辑  收藏 所属分类: Linux shell 入门
首先看看/etc/passwd
它保存着用户名、加密后的密码等信息,我们登录系统所有信息都要在里面查找
Shell代码
  1. -bash-3.00$ cat /etc/passwd | tr ":" "\t" | sort -k0   
  2. adm     x       4       4       Admin   /var/adm   
  3. bin     x       2       2               /usr/bin   
  4. daemon  x       1       1               /   
  5. gdm     x       50      50      GDM Reserved UID        /   
  6. jiang   x       100     1               /       /bin/sh   
  7. listen  x       37      4       Network Admin   /usr/net/nls   
  8. lp      x       71      8       Line Printer Admin      /usr/spool/lp   
  9. noaccess        x       60002   60002   No Access User  /   
  10. nobody  x       60001   60001   NFS Anonymous Access User       /   
  11. nobody4 x       65534   65534   SunOS 4.x NFS Anonymous Access User     /   
  12. nuucp   x       9       9       uucp Admin      /var/spool/uucppublic      
  13.   
  14. /usr/lib/uucp/uucico   
  15. root    x       0       0       Super-User      /       /bin/bash   
  16. smmsp   x       25      25      SendMail Message Submission Program     /   
  17. sys     x       3       3               /   
  18. ttaserv x       101     100             /       /bin/sh   
  19. ttasys  x       102     100             /       /bin/sh   
  20. uucp    x       5       5       uucp Admin      /usr/lib/uucp   
  21. webservd        x       80      80      WebServer Reserved UID  /   
  22. www     x       81      81      WebServer User  /   
  23. -bash-3.00$ cat /etc/passwd | sed -n  '/jiang/'p   
  24. jiang:x:100:1::/:/bin/sh   
  25. -bash-3.00$ cat /etc/passwd | sed -n  '/jiang/'p | tr ':' '\t'  
  26. jiang   x       100     1               /       /bin/sh  


用户登录时自动读取/etc/profile 此文件包含:
  • 全局或局部环境变量。
  • PATH信息
  • 终端设置
  • 安全命令
  • 日期信息或放弃操作信息

让我们来看一个详细的profile
Shell代码
  1. -bash-3.00$ cat /etc/profile   
  2. #ident  "@(#)profile    1.19    01/03/13 SMI"   /* SVr4.0 1.3   */   
  3.   
  4. # The profile that all logins get before using their own .profile.   
  5.   
  6. trap ""  2 3 #忽略两个信号,即使用QUIT退出或<Ctrl-c>键停止文件执行   
  7.   
  8.   
  9. ulimit -d 100000 #限制内存溢出,设置数据段的最大值:单位kbytes   
  10. export LOGNAME PATH #导出LOGNAME 和 PATH   
  11. export LANG=C #设置语言环境   
  12. if [ "$TERM" = "" ] #设置终端类型   
  13. then   
  14.         if /bin/i386   
  15.         then   
  16.                 TERM=sun-color   
  17.         else   
  18.                 TERM=sun   
  19.         fi   
  20.         export TERM   
  21. fi   
  22.   
  23. #       Login and -su shells get /etc/profile services.   
  24. #       -rsh is given its environment in its .profile.   
  25.   
  26. case "$0" in   
  27.   
  28. -sh | -ksh | -jsh | -bash)   
  29.   
  30.         if [ ! -f .hushlogin ]   
  31.         then   
  32.                 /usr/sbin/quota   
  33.                 #       Allow the user to break the Message-Of-The-Day only.   
  34.                 trap "trap '' 2"  2  
  35.                 /bin/cat -s /etc/motd   
  36.                 trap "" 2  
  37.   
  38.                 /bin/mail -E   
  39.                 case $? in #建立邮件信息(当有新邮件到达时显示提示信息)   
  40.                 0)   
  41.                         echo "You have new mail."  
  42.                         ;;   
  43.                 2)   
  44.                         echo "You have mail."  
  45.                         ;;   
  46.                 esac   
  47.         fi   
  48. esac   
  49.   
  50. umask 022 #设置umask值,使文件创建时带有一定的缺省权限位集   
  51. trap  2 3 #重新设置捕捉信号<Ctrl-C>和QUIT,即恢复信号量的默认操作   
  52.   
  53. # add by jianghua   
  54.   
  55. export   
  56. PATH=$PATH:/usr/local/bin:/usr/local/mysql/bin:/opt/SunStudio_11/SUNWspro/bin:/usr/ccs/bin:   
  57.   
  58. /usr/sfw/bin:.   
  59. export HISTSIZE=1000  
  60. export HISTFILESIZE=1000  
  61. #   
  62. # Show Unix-Center.Net Welcome Message in Chinese   
  63. #   
  64. show_welcome_message  


用户的$HOME.profile
下面显示如何在命令提示符中设置主机名:
Shell代码
  1. -bash-3.00$ PS1='$PWD >'  
  2. /home/l/g/tomotoboy >export PS1  


stty用于设置终端特性。要查询现在的stty选项,使用stty -a
Shell代码
  1. /home/l/g/tomotoboy >stty -a   
  2. speed 9600 baud;   
  3. rows = 25; columns = 82; ypixels = 0; xpixels = 0;   
  4. csdata ?   
  5. eucw 1:0:0:0, scrw 1:0:0:0  
  6. intr = ^c; quit = ^\; erase = ^?; kill = ^u;   
  7. eof = ^d; eol = <undef>; eol2 = <undef>; swtch = <undef>;   
  8. start = ^q; stop = ^s; susp = ^z; dsusp = ^y;   
  9. rprnt = ^r; flush = ^o; werase = ^w; lnext = ^v;   
  10. -parenb -parodd cs8 -cstopb -hupcl cread -clocal -loblk -crtscts -crtsxoff -parext   
  11.   
  12. -ignbrk brkint -ignpar -parmrk -inpck -istrip -inlcr -igncr icrnl -iuclc   
  13. ixon -ixany -ixoff imaxbel   
  14. isig icanon -xcase echo echoe echok -echonl -noflsh   
  15. -tostop echoctl -echoprt echoke -defecho -flusho -pendin iexten   
  16. opost -olcuc onlcr -ocrnl -onocr -onlret -ofill -ofdel tab3  


创建.logout文件
Shell代码
  1. trap "$HOME /.logout " 0  
  2.   
  3. /home/l/g/tomotoboy >cat .logout   
  4. rm -f $HOME/*.txt   
  5. rm -f $HOME/*.tmp   
  6. rm -f $HOME/x*   
  7. echo "Bye...bye $LOGNAME"  

只有注册用户登录后才能发表评论。


网站导航: