posts - 3, comments - 0, trackbacks - 0, articles - 1
  C++博客 :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理

Create A Share Directory for Linux Users

Posted on 2011-12-13 14:16 CT 阅读(147) 评论(0)  编辑 收藏 引用
Linux shell commands which will be used: groupadd, useradd, usermod, gpasswd, id, mkdir, ll, chgrp, chmod, su, cd, touch.
// Note: '#' is used as command prompt.

1) use perl as script to handle the new users adding.
#!/usr/bin/perl
$user=$ARGV[0];
$passwd=$ARGV[1];
if (!$user || !$passwd)
{
   print "Note: user name and passwd cannot be NULL.\n";
   exit 0;
}
@saltchars = (a..z, A..Z, 0..9); # as a whole for assignment
srand(time || $$);
$salt = $saltchars[rand($#saltchars)].$saltchars[rand($#saltchars)]; # $# is the last index of array
$encrypt_passwd = crypt($passwd, $salt);
$add_exec = "/usr/sbin/useradd -p ".$encrypt_passwd." ".$user;                                
print $add_exec."\n ";
system($add_exec);
#This perl script runs well in perl v5.10.1 built for i386-linux-thread-multi using root permission.
#saved this file as user_add.pl and
#chmod u+x user_add.pl
#./user_add.pl Tom 123456
#./user_add.pl Lily 123456
2) groupadd project; gpasswd -a Tom project; gpasswd -a Lily project; id Tom; id Lily;
3) mkdir /home/workspace; chgrp project /home/workspace; chmod 2770 /home/workspace;
#Now, directory '/home/workspace' can be shared by Tom and Lily for working or studying together.
#su, cd, touch, ll and other shell commands can be used to do a testing.

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理