Results 1 to 3 of 3
Hi all,
I am struggling to write a bash script which can perform the following
functions:
1. Script should present a menu to carry out basic command like user addition, ...
- 09-15-2008 #1Just Joined!
- Join Date
- Sep 2008
- Posts
- 1
User addition script
Hi all,
I am struggling to write a bash script which can perform the following
functions:
1. Script should present a menu to carry out basic command like user addition, user modofication and user deletion
2. An automated password should be generated by script and store
in the user home directory
3. It should also generate ssh keys placing public key in the root folder
of home directory and secret key in the ssh directory of user
4. It should also check while adding new user whether it exists or not and if
user exists it should provide alternatives.
Any help from anyone will be highly appreciated.Thanks in advace.
Cheers
Florence
- 09-15-2008 #2
An option to make menus to execute scripts & system commands is programming in python with the addition of the curses library. Using system commands in Python is extremely easy.
Python HOWTOs
Curses Programming with Python
- 09-18-2008 #3Linux User
- Join Date
- May 2008
- Location
- NYC, moved from KS & MO
- Posts
- 251
1. For simple menus, select statement can do a very good job, for example
2. For random password generation, you can use this simple python scriptCode:#!/bin/bash PS3="What do you want to do? " select action in 'Add' 'Modify' 'Delete' 'Quit' do case $REPLY in 1) echo "Addn user" #user adding commands ;; 2) echo "Modify user" #user modifying commands ;; 3) echo "Delete user" #user adding commands ;; 4) break ;; esac done
3. ssh-keygen with some options should do the work, do a man ssh-keygen you should be able to get what you need. To automate the process, you will need at least -f to specify the output keyfile and -N to specify the passphrase, the following example with generate a keyfile for testuserCode:#!/bin/env python import string from random import choice size=9 passwd=''.join([choice(string.letters+string.digits) for i in range(size)]) print passwd
ssh-keygen -f /home/testuser/.ssh/testuser_rsa -N ''
The public key file will be /home/testuser/.ssh/testuser_rsa.pub
After that, do a
cat /home/testuser/.ssh/testuser_rsa >> /root/.ssh/authorized_keys2
( I don't understand why you want to put the public keys under /home ? Usually it's placed under a specific user's home dir )
4. Do a simple grep should be enough to tell if a user exists or not, like this
grep ^testuser /etc/password


Reply With Quote