LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 923|回复: 7

求客户端自动申请shell帐号的login 脚本.

[复制链接]
发表于 2004-12-20 10:59:59 | 显示全部楼层 |阅读模式
希望完成的功能:在login的提示符号下,输入new,指引用户自动完成shell帐号的申请.怎么实现都可以。
哪位高手帮忙啊。
发表于 2004-12-20 11:22:36 | 显示全部楼层
这要修改login程序才能作到吧
 楼主| 发表于 2004-12-20 11:30:28 | 显示全部楼层
怎么修改啊。
我琢磨着能不能写个脚本,弄个同样的名字,设置比系统的login优先执行啊。
发表于 2004-12-20 11:45:26 | 显示全部楼层
Post by myge
怎么修改啊。
我琢磨着能不能写个脚本,弄个同样的名字,设置比系统的login优先执行啊。

引一段文字先
  1. Getty is the program that enables you to log in through a serial device such as a virtual terminal, a text terminal, or a modem. It displays the login prompt. Once you enter your username, getty hands this over to login which asks for a password, checks it out and gives you a shell.

  2. There are many getty's available. Some distributions, including Red Hat use a very small one called mingetty that only works with virtual terminals.
复制代码
这就是说,你要看一下系统是用哪一个getty程序,一般用mingetty或agetty
然后替换掉它,但这比较麻烦,因为它还会转移到login程序,最好能看一下getty的实现
这一般是在util-linux包里
发表于 2004-12-20 12:00:07 | 显示全部楼层
Post by myge
怎么修改啊。
我琢磨着能不能写个脚本,弄个同样的名字,设置比系统的login优先执行啊。


这个的实现比较复杂

我这里可以提供一个较简单实用的方案:
设置一个申请帐号,例如:new,密码也为:new
这个帐号一登录进去就执行一个脚本程序(此程序为申请shell帐号的脚本,具体如何写本版置顶精华一定能帮上忙),执行完之后脚本就自动退出new用户。

上面这个方案的执行关键之处是如何此用户一登录执行完脚本就退出,我想出并测试了一下:将new用户的登录shell改成那个脚本。此方法可以实现。
发表于 2004-12-20 18:09:00 | 显示全部楼层
Post by kiron
这个的实现比较复杂

我这里可以提供一个较简单实用的方案:
设置一个申请帐号,例如:new,密码也为:new
这个帐号一登录进去就执行一个脚本程序(此程序为申请shell帐号的脚本,具体如何写本版置顶精华一定能帮上忙),执行完之后脚本就自动退出new用户。

上面这个方案的执行关键之处是如何此用户一登录执行完脚本就退出,我想出并测试了一下:将new用户的登录shell改成那个脚本。此方法可以实现。

嗯,这到是个变通的方法
可以试一下
发表于 2004-12-20 18:40:07 | 显示全部楼层
  1. #!/bin/bash
  2. #
  3. #.bashrc (Use to add new user for openlab).
  4. #
  5. # To prevent the quit for system secrity.
  6. #
  7. trap "" 2

  8. # Modify group, logfile:
  9. #
  10. GROUP="users"
  11. LOGFILE="userlog"

  12. # main script file
  13. # Can modify some infomations follow the "echo"
  14. # eg: welcome informations or error infomatons.
  15. #
  16. # Welcome informations
  17. #
  18. clear
  19. echo "-=====================================================================-"
  20. echo "-                  W e l c o m e T o T h e O p e n l a b              -"
  21. echo "-=====================================================================-"
  22. echo
  23. echo "Please follow the steps to create your own account!"

  24. for try in 1 2 3 4 5
  25. do
  26.         echo
  27.         echo -n "Please enter your new own account:"
  28.         read ACC
  29.         ##
  30.         if echo "$ACC" | grep '[^a-z0-9]' > /dev/null
  31.                 then
  32.                         echo  
  33.                         echo "name should be all alphanumeric, '-', '_', '.'."
  34.         elif echo "$ACC" | grep '^[a-z]' > /dev/null
  35.                 then
  36.                 if `adduser "$ACC" -g "$GROUP" -d /"$GROUP"/"$ACC"`
  37.                         then
  38.                         echo
  39.                         echo "Please enter your password, sugessted longer than "6" !!!"
  40.                         echo
  41.                         passwd $ACC
  42.                
  43.                         # Sucessfull infomation
  44.                         #
  45.                         echo
  46.                         echo "Congratulations, your own account was created."
  47.                         echo "You should relogin later with your new account."
  48.                
  49.                         # userlog, contains account created in the system               
  50.                         #
  51.                         echo "$ACC" | cat >> "$LOGFILE"
  52.                         # standby 5 seconds
  53.                         #
  54.                         sleep 5
  55.                         exit
  56.                         else :
  57.                 fi
  58.         else
  59.                 echo
  60.                 echo "account must begin with lowercase character."
  61.         fi
  62. done

  63. # Many faild times or too errors to create new account.
  64. #
  65. echo "You are trying too many times."
  66. echo "Please try it next time."
  67. sleep 4
  68. exit
复制代码


不知这个能行不?

很早以前写的一个,在实验室用过.可以对其中的参数进行酌情修改.

具体的使用方法, 建立一个具有root权限的用户, 把它的.bashrc进行替换.,, 就能使用那个用户名登陆和建立帐号了.当然,脚本是无法中断的, 所以,不用担心系统的安全问题.
 楼主| 发表于 2004-12-23 19:14:29 | 显示全部楼层
谢谢各位高手帮忙啊。虽然我看不太懂,还是试一试先。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表