LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
Search this Thread
Old 11-02-2008, 03:39 AM   #1
Tim356
LQ Newbie
 
Registered: May 2006
Distribution: RHEL 5.2
Posts: 27

Rep: Reputation: 15
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?
 
Old 11-02-2008, 05:40 AM   #2
unSpawn
Moderator
 
Registered: May 2001
Posts: 27,140
Blog Entries: 54

Rep: Reputation: 2791Reputation: 2791Reputation: 2791Reputation: 2791Reputation: 2791Reputation: 2791Reputation: 2791Reputation: 2791Reputation: 2791Reputation: 2791Reputation: 2791
Quote:
Originally Posted by Tim356 View Post
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 View Post
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.
 
Old 11-02-2008, 06:49 AM   #3
Tim356
LQ Newbie
 
Registered: May 2006
Distribution: RHEL 5.2
Posts: 27

Original Poster
Rep: Reputation: 15
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:
 
Old 11-02-2008, 07:47 AM   #4
unSpawn
Moderator
 
Registered: May 2001
Posts: 27,140
Blog Entries: 54

Rep: Reputation: 2791Reputation: 2791Reputation: 2791Reputation: 2791Reputation: 2791Reputation: 2791Reputation: 2791Reputation: 2791Reputation: 2791Reputation: 2791Reputation: 2791
Quote:
Originally Posted by Tim356 View Post
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?
 
Old 11-05-2008, 06:44 AM   #5
Tim356
LQ Newbie
 
Registered: May 2006
Distribution: RHEL 5.2
Posts: 27

Original Poster
Rep: Reputation: 15
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.
 
Old 11-05-2008, 12:14 PM   #6
unSpawn
Moderator
 
Registered: May 2001
Posts: 27,140
Blog Entries: 54

Rep: Reputation: 2791Reputation: 2791Reputation: 2791Reputation: 2791Reputation: 2791Reputation: 2791Reputation: 2791Reputation: 2791Reputation: 2791Reputation: 2791Reputation: 2791
Quote:
Originally Posted by Tim356 View Post
I'm actually doing some study - and in a lab question I have
May I suggest you read the material accompanying your study (again)?
 
Old 11-05-2008, 09:49 PM   #7
Tim356
LQ Newbie
 
Registered: May 2006
Distribution: RHEL 5.2
Posts: 27

Original Poster
Rep: Reputation: 15
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.
 
Old 11-05-2008, 10:32 PM   #8
i92guboj
Gentoo support team
 
Registered: May 2008
Location: Lucena, Córdoba (Spain)
Distribution: Gentoo
Posts: 4,038

Rep: Reputation: 373Reputation: 373Reputation: 373Reputation: 373
Quote:
Originally Posted by Tim356 View Post
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 View Post
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 View Post
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
BASH - How to open an interactive script from a non interactive script..... OldGaf Programming 4 06-29-2008 04:34 PM
interactive and non-interactive shell linuxjamil Programming 3 09-03-2006 08:42 PM
write interactive c++ christina_rules Programming 7 06-21-2006 01:07 PM
non-interactive ssh podollb Linux - Software 3 04-20-2004 03:28 PM
Non interactive FTP lapthorn Linux - Networking 1 11-25-2003 04:00 AM


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

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration