ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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.
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/
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.
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.
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.