LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Interactive and non-interactive shells? (https://www.linuxquestions.org/questions/linux-newbie-8/interactive-and-non-interactive-shells-680599/)

Tim356 11-02-2008 03:39 AM

Interactive and non-interactive shells?
 
What is the difference between an interactive shell and a non-interactive shell? And how can you make sure a user does not have an interactive shell?

unSpawn 11-02-2008 05:40 AM

Quote:

Originally Posted by Tim356 (Post 3328919)
What is the difference between an interactive shell and a non-interactive shell?

From 'man bash', under INVOCATION: "An interactive shell is one started: without non-option arguments and without the -c option whose standard input and error are both connected to terminals (..), or one started with the -i option.".


Quote:

Originally Posted by Tim356 (Post 3328919)
And how can you make sure a user does not have an interactive shell?

Depends on the reason why you want or need it. For unprivileged users that could be denying login, for system users that could be setting the shell to an inert shell like /sbin/nologin or /bin/false.

Tim356 11-02-2008 06:49 AM

Would simply removing the reference to the particular shell for a specific user in the /etc/passwd file achieve the same thing?

ie change:
Code:

testuser:x:501:501::/home/testuser:/bin/bash
to

Code:

testuser:x:501:501::/home/testuser:

unSpawn 11-02-2008 07:47 AM

Quote:

Originally Posted by Tim356 (Post 3329021)
Would simply removing the reference to the particular shell for a specific user in the /etc/passwd file achieve the same thing?

No it wouldn't. (GNU/Linux is free and not only in the context of payment concepts, it also means you may experiment at will. Try it. You'll like it.) I posted an example, so if those are not valid for your situation, what exactly are you trying to achieve?

Tim356 11-05-2008 06:44 AM

I'm actually doing some study - and in a lab question I have (which unfortunately offers no explanation) the question states "Create users x, y and z. Ensure user x can only login with a non-interactive shell."

Therefore /sbin/nologin and /bin/false will not work in this example as I need to be able to login with the user.

unSpawn 11-05-2008 12:14 PM

Quote:

Originally Posted by Tim356 (Post 3332338)
I'm actually doing some study - and in a lab question I have

May I suggest you read the material accompanying your study (again)?

Tim356 11-05-2008 09:49 PM

Oh hang on, read the material accompanying my study - what a great idea! Oh hang on, I HAVE READ IT AND IT:
Quote:

...unfortunately offers no explanation
So what would I do if I couldn't find the explanation in my study material? Hmm...maybe do a bit of research, maybe find a helpful forum to ask questions about linux. Like...I don't know... LinuxQuestions.org.

How about instead of offering abuse when you don't know the answer, just keep quiet? Great way to help someone seeking advice - get sarcastic.

i92guboj 11-05-2008 10:32 PM

Quote:

Originally Posted by Tim356 (Post 3328919)
What is the difference between an interactive shell and a non-interactive shell? And how can you make sure a user does not have an interactive shell?

I think that the other user above already answered that. However, I really advice you to read the INVOCATION section of the bash man page if you haven't yet (if you have already then that's almost everything about it).

A tipical interactive shell presents you a prompt where you can enter commands and read the output. Technically speaking, all of stderr, stdout and stdin are connected to a tty-like interface.

On the contrary, when the shell's non-interactive you can't -well- interact with it. A tipical example is when you run a script. That script is run into a non-interactive shell, which in bash can be checked echoing the contents of $- and checking that "i" is not present on that string.

About the user. Well. It depends on what do you mean. A non interactive shell wouldn't be of much use for a human user unless it's used to launch anything else. Try to explain a bit better what do you mean or what do you try to achieve.


Quote:

Originally Posted by Tim356 (Post 3329021)
Would simply removing the reference to the particular shell for a specific user in the /etc/passwd file achieve the same thing?

If you remove the shell, the sh will be used since it's the default. That has nothing to do with the shell being interactive or not.



Quote:

Originally Posted by Tim356 (Post 3332338)
I'm actually doing some study - and in a lab question I have (which unfortunately offers no explanation) the question states "Create users x, y and z. Ensure user x can only login with a non-interactive shell."

Therefore /sbin/nologin and /bin/false will not work in this example as I need to be able to login with the user.

I really don't get what they mean, unless they are asking you to use a silly thing like a script that does whatever and then exits or sits there forever. There's no easy way to interact with a non-interactive shell, at most you can interact with your script which might be a menu, or launch another shell (interactive one) or whatever. I really don't get the point of that question.

If that's what they want, you could just use startx as your shell. That will guarantee that a non-interactive shell will be run.


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