LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 05-21-2011, 05:53 AM   #1
adash
LQ Newbie
 
Registered: May 2011
Posts: 3

Rep: Reputation: Disabled
[bash scripting] logging to the virtual account


Hi guys!
I need to write a bash script that will allow me to manage my "virtual network" (in reality just a bunch of directories and files).

I need to obtain something like : I have my own command 'connect'. We can use it in two different modes: user and admin.

If I type 'connect adashiu virtual_machine_name, computer will ask about password, if password is correct he will change a prompt to :

adashiu_at_virtual_machine_name >

after that user can start to use commands reserved only for user mode.

Analogically with admin mode: prompt 'admin >' and administrator can only use bunch of commands reserved for him.

Can anyone tell me how to solve this problem with changing prompt and separated commands for user and admin ?

Thank you in advance and
sorry for my english

Adam
 
Old 05-21-2011, 06:21 AM   #2
crts
Senior Member
 
Registered: Jan 2010
Posts: 2,020

Rep: Reputation: 757Reputation: 757Reputation: 757Reputation: 757Reputation: 757Reputation: 757Reputation: 757
Quote:
Originally Posted by adash View Post
Hi guys!
I need to write a bash script that will allow me to manage my "virtual network" (in reality just a bunch of directories and files).

I need to obtain something like : I have my own command 'connect'. We can use it in two different modes: user and admin.

If I type 'connect adashiu virtual_machine_name, computer will ask about password, if password is correct he will change a prompt to :

adashiu_at_virtual_machine_name >

after that user can start to use commands reserved only for user mode.

Analogically with admin mode: prompt 'admin >' and administrator can only use bunch of commands reserved for him.

Can anyone tell me how to solve this problem with changing prompt and separated commands for user and admin ?

Thank you in advance and
sorry for my english

Adam
Hi and welcome to LQ,

what have you tried so far? Where are you stuck?
Not sure what you are exactly trying to do but have you considered using sudo? sudo can not only be used to gain root privileges but also to restrict normal user access. You have to modify the file /etc/sudoers accordingly to allow/restrict users to execute commands.
Type in a terminal
Code:
man sudo
man sudoers
to get more detailed information. You might not have to write a complex script.
 
Old 05-21-2011, 07:59 AM   #3
adash
LQ Newbie
 
Registered: May 2011
Posts: 3

Original Poster
Rep: Reputation: Disabled
I think that sudo is a command to switch for superuser.

My task to do is :
in file users.txt I have 2 users defined(virtual).

adash|pass|admin
user1|pass|user

i type 'connect user1 machine_name'
then password

If all is ok,
the prompt is changing to 'user1@machine_name >' and the user1 is able only to use custom commands reserved for user.

Hard to explain, hopes you understand me.
 
Old 05-21-2011, 08:12 AM   #4
crts
Senior Member
 
Registered: Jan 2010
Posts: 2,020

Rep: Reputation: 757Reputation: 757Reputation: 757Reputation: 757Reputation: 757Reputation: 757Reputation: 757
Quote:
Originally Posted by adash View Post
I think that sudo is a command to switch for superuser.
No, it is not. As I wrote in my previous post it can be used to switch to any user.

Anyway, this does sound like homework. Posting homework assignments is against LQ rules.

Since you state that there are no "real" machines (not even virtual machines) involved but just a bunch of directories, my guess is that your instructor has a solution with 'chroot' in mind. Have a look at the manpage:
man chroot

Again, you will have to put in some effort for yourself.
Here is some more reading that will be very helpful:
http://tldp.org/LDP/abs/html/
 
Old 05-21-2011, 08:15 AM   #5
carltm
Member
 
Registered: Jan 2007
Location: Canton, MI
Distribution: CentOS, SuSE, Red Hat, Debian, etc.
Posts: 703

Rep: Reputation: 99
Quote:
Originally Posted by adash View Post
Can anyone tell me how to solve this problem with changing prompt and separated commands for user and admin ?
I don't understand what you want to change.

Do you want the user to not get asked for a password?

Once a user has entered the password, does everything work correctly?
If not, what is not right?
 
Old 05-21-2011, 08:19 AM   #6
carltm
Member
 
Registered: Jan 2007
Location: Canton, MI
Distribution: CentOS, SuSE, Red Hat, Debian, etc.
Posts: 703

Rep: Reputation: 99
Quote:
Originally Posted by crts View Post
No, it is not. As I wrote in my previous post it can be used to switch to any user.
Well, technically sudo isn't the command to switch to any user.
That command is su. Sudo lets you run a single command with
the permissions of root. Of course you can use a combination
of sudo and su to run a command as any user.
 
Old 05-21-2011, 08:47 AM   #7
crts
Senior Member
 
Registered: Jan 2010
Posts: 2,020

Rep: Reputation: 757Reputation: 757Reputation: 757Reputation: 757Reputation: 757Reputation: 757Reputation: 757
Quote:
Originally Posted by carltm View Post
Well, technically sudo isn't the command to switch to any user.
That is correct. The -i option, however, simulates a login shell. With an according modification of the sudoers file you can do anything that the "real" user could do.
Quote:
Sudo lets you run a single command with
the permissions of root. Of course you can use a combination
of sudo and su to run a command as any user.
From the manpage:
Code:
       -i [command]
                   The -i (simulate initial login) option runs the shell
                   specified in the passwd(5) entry of the target user as a
                   login shell.  This means that login-specific resource files
                   such as .profile or .login will be read by the shell.  If a
                   command is specified, it is passed to the shell for
                   execution.  Otherwise, an interactive shell is executed.
                   sudo attempts to change to that user's home directory
                   before running the shell.  It also initializes the
                   environment, leaving DISPLAY and TERM unchanged, setting
                   HOME, MAIL, SHELL, USER, LOGNAME, and PATH, as well as the
                   contents of /etc/environment on Linux and AIX systems.  All
                   other environment variables are removed.
...
       -u user     The -u (user) option causes sudo to run the specified
                   command as a user other than root.  To specify a uid
                   instead of a user name, use #uid.  When running commands as
                   a uid, many shells require that the '#' be escaped with a
                   backslash ('\').  Note that if the targetpw Defaults option
                   is set (see sudoers(5)) it is not possible to run commands
                   with a uid not listed in the password database.
So, if I understand correctly, the 'sudo su' construct is not required to "switch" to another user.
 
Old 05-21-2011, 09:31 AM   #8
Chirel
Member
 
Registered: Nov 2009
Posts: 55

Rep: Reputation: 19
Hi,

I think like crts that your instructor have a solution based on chroot.

Just go read and learn how to do it.
 
Old 05-21-2011, 10:35 AM   #9
adash
LQ Newbie
 
Registered: May 2011
Posts: 3

Original Poster
Rep: Reputation: Disabled
Yeah it's homework ( a project ) it's really 1/100 of this project. It's just a beggining and I'm stuck because I don't know some basis.

This project is to create a "virtual network" meaning a tree of directories (as virtual machines) and files to manage users etc.
I need to elaborate a command 'connect' in 2 modes user and admin.

Admin will have bunch of separated commands to create a new user, new machine etc.

User will be able to connect virtually to a machine (phisically just a name of a user will be added to machine/logged_users.txt)

The thing is I cannot start developping all the rest of the project (commands for admin and user) if I don't know how to make a login thing.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
problem logging into root account pcdsi Linux - Newbie 17 05-15-2009 04:02 PM
Logging out a user account within a script kaplan71 Linux - Software 2 03-14-2009 12:07 AM
Virtual Email Account for virtual domain in Postfix javed_dogar Linux - Server 7 10-17-2008 12:31 PM
Prevent user account from logging in but allow su to account DejaCpp Linux - General 4 07-26-2006 11:44 AM
Logging account lockout sbrewer Linux - Security 1 10-22-2005 03:48 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:11 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration