LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
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 10-05-2003, 03:13 AM   #1
SpecialK5106
LQ Newbie
 
Registered: Oct 2003
Location: Gainesville, FL
Distribution: Slackware 9.1
Posts: 17

Rep: Reputation: 0
How to check if login is from localhost


Hi, I'm using Slackware 9, and I want to start X and go into the window manager immediately when logging into some accounts. However, with others, such as root, I just want to login to the command line. So, I figured that I could just put "startx" in the .bash_profile, but what will happen when the user logs in remotely? I'm eventually going to set up the ssh server, so I want to prevent any errors now. Is there any simple way to check if the login is local (and then startx if it is)?

Also, one the problems I'm having as a new Linux user is finding in exactly what configuration file I need to make a change. Specifically, I want to mount the cd-rom and floppy for every user on startup. What file should this be done in? And is there some website that lists what the most important config files are and what should go in them?

Thanks for the help,
Mark
 
Old 10-05-2003, 04:26 AM   #2
scott_R
Member
 
Registered: Jul 2003
Location: Brighton, Michigan, USA
Distribution: Lots of distros in the past, now Linux Mint
Posts: 748

Rep: Reputation: 31
My preference is to make separate logins for local and remote users. This is mostly for logging and security purposes. Often times you'll want to limit remote users access to files, especially when corporate, government or military secrets are involved, even though the remote user would normally have full access to such information while at a localized computer. Some people will try to argue, but if you present it properly, there is no real argument against this setup. This kind of setup might also help your situation, where you might want totally different programs available to someone on a 56k connection, than someone on your lan. (X, is a good example.)

For your drive question, fstab is probably your choice. 'man fstab' should give you some hints. Automounting might be an option, or using the 'user' or 'users' option may be what you're looking for. It depends on your needs, of course.

As far as important config files, anything in man page 5 is important. Man 5 deals specifically with config files. if you're new to man pages, you can access them through the console (the DOS looking thing). 'man man' contains instructions for using the manual page system. (Hint: 'q' is to exit.) 'info' is also another great source for linux information.

Don't try to understand everything at once. This is where people get confused. Just look for what you need to know, and work from there.

Other important files to know: .profile (in you home directory, also in /etc [/etc ones count towards all users]--they contain setup information for your users, as do .bashrc files--one is for original login, the other is for each time you start a terminal). XF86Config(-4) -- the X system configuration file.

Other than that, you can probably get by learning the other configs as you go. If you use dial-up, it wouldn't hurt to learn about ppp configuration either, even though most of it is automated nowadays, remote use may necessitate your advanced knowledge.
 
Old 10-05-2003, 04:21 PM   #3
SpecialK5106
LQ Newbie
 
Registered: Oct 2003
Location: Gainesville, FL
Distribution: Slackware 9.1
Posts: 17

Original Poster
Rep: Reputation: 0
Thanks for the help. I did end up using the "user" option in the fstab for the cdrom and floppy.

I see what you're saying with the separate logins. So, for example, I could make two accounts for a user that would be logging in via the console and lan. And then I would allow the user to only login to the console-specific account at the console, and vise-versa. But where do these settings go? In the config files for each server, I'm guessing, but what about local logins? How do I prevent a local user from logging into a remote-only account?

However, in my specific case, I think I will just be using the computer myself. I want to be able to automatically use X when logging in from home. When I am at school, I would like to be able access all my files (most likely through a command-line interface such as putty or psftp), so I can't have the "startx" command alone in .bash_profile. I was hoping I would be able to do something like this:
if(login from localhost){
startx
}
Is something like that possible?

Thanks,
Mark
 
Old 10-06-2003, 02:17 AM   #4
praveenk
Member
 
Registered: Oct 2003
Location: /india/tn/chennai/vadapalani/hcl/networking
Distribution: Debian GNU/Linux SID, FreeBSD
Posts: 59

Rep: Reputation: 15
Use TTY value!

In Linux, the terminal number is assigned with every login. For local users, the TTY values are from 0-9 like tty0, tty1, etc. But for remote users, it's ptty0, ptty1, etc. So, in your shell script match the environment variable $TTY with the starting pattern 'tty' and not 'ptty'. This may work out well for you. Is that enough?
 
Old 10-13-2003, 01:43 AM   #5
SpecialK5106
LQ Newbie
 
Registered: Oct 2003
Location: Gainesville, FL
Distribution: Slackware 9.1
Posts: 17

Original Poster
Rep: Reputation: 0
Thanks, praveenk. However, there doesn't seem to be a TTY environment variable ($TTY on the command-line returns nothing), but there is a command tty that returns the name. I guess I could run it in the login script and then check its output. How would the comparison be done?

But when I first posted I figured this was a pretty common problem. Is it just the case that separate accounts are typically made for local and remote logins, as scott_R had suggested?
 
Old 10-13-2003, 04:14 AM   #6
praveenk
Member
 
Registered: Oct 2003
Location: /india/tn/chennai/vadapalani/hcl/networking
Distribution: Debian GNU/Linux SID, FreeBSD
Posts: 59

Rep: Reputation: 15
SpecialK5106, you need not have separate logins for remote and local users. That is not a good way to do it. I will tell you the simple way to do it with your bashrc or bash_profile

A=`tty`
B="tty"
if [ $A < $B ]; then
# Commands for remote login here.
else
# Commands for local login here.
fi

Note: Since ptty < tty*, this should work fine. You may also used sed or awk to match patterns, but that will make the work complicated. This is a simple way and it should work fine.
 
Old 10-13-2003, 04:53 AM   #7
hw-tph
Senior Member
 
Registered: Sep 2003
Location: Sweden
Distribution: Debian
Posts: 3,032

Rep: Reputation: 58
Nice trick praveenk, I will surely try to use it (or a variant) in some of my scripts!

hw
 
Old 10-13-2003, 05:40 AM   #8
yapp
Member
 
Registered: Apr 2003
Location: Netherlands
Distribution: SuSE (before: Gentoo, Slackware)
Posts: 613

Rep: Reputation: 30
Re: How to check if login is from localhost

FYI: A xterm also uses pts/? devices, like your ssh connection. It's the way a terminal device connects to your system; as terminal (serial line, or virtual terminal), or remote console (xterm, telnet, ssh)

I'm just curious why you want to "startx" when a user logs in. You could set the runlevel of the systems to 4 or 5, to get a graphical login.

Quote:
Originally posted by SpecialK5106
Specifically, I want to mount the cd-rom and floppy for every user on startup.
You can't. You mount a device to 'hook' the file system into your file hierachy. You can't mount untill you have inserted a disk, and should unmount if you remove the disk. It's like adding a network share in Microsoft Windows (and you'll see another drive letter.. this can't be done automatically if the server is unavailable)

For example, a floppy disk won't be written untill the cache is full / the "syn" command clears the cache, or you unmount (which calls sync)

You can try to use "supermount", or "automount", but there is another thing. Add a kde desktop shortcut. If you click on the the shortcut, the KDE will mount the device automatically. (And can press "umount / eject" in the context menu of your right mouse.) But I'm wondering... do you really want people to insert CD disks? (It has been limited to the root user by default for a security reason)

Last edited by yapp; 10-13-2003 at 05:45 AM.
 
Old 10-13-2003, 07:36 PM   #9
SpecialK5106
LQ Newbie
 
Registered: Oct 2003
Location: Gainesville, FL
Distribution: Slackware 9.1
Posts: 17

Original Poster
Rep: Reputation: 0
Thanks for the suggestion, praveenk, but it doesn't seem to work in that form. The command tty returns /dev/tty# from a local login and /dev/pts/# from a remote login. So, I tried this:

A='tty'
B="/dev/tty"
if [ $A > $B ]; then
#local commands
fi

The if block is entered no matter whether I'm using < or >. If I type $A afterwards, then I correctly get /dev/pts/# or /dev/tty#, but $B results in -bash: /dev/tty: Permission denied.


>>I'm just curious why you want to "startx" when a user logs in.

yapp, I installed Linux for the first time on an old 133MHz Pentium that I got. I want to make the boot time as short as possible, so I want a text login. Also, as I'm learning to configure everything as root, I don't need a GUI. But, I do want at least one user account that automattically starts a window manager, so I put "startx" in that user profile.


>>do you really want people to insert CD disks? (It has been
>> limited to the root user by default for a security reason)

Yeah, I just was accustomed to Windows, so I got a little sick of typing mount /dev/cdrom /mnt/cdrom every time I wanted to access the CD. Now that everything is installed, I no longer have that need. Also, now I understand a little more of why it's done that way.


>>Add a kde desktop shortcut.

The system's a little slow for kde :-). I'm now using Blackbox, which brings me to another question. What's the fastest graphical web browser out there? I tried Mozilla, but was a bit disappointed. I've also heard about Opera and Firebird. How are they?
 
Old 10-14-2003, 12:19 AM   #10
rahulsundaram
Member
 
Registered: May 2003
Location: India
Distribution: Knoppix, RedHat
Posts: 246

Rep: Reputation: 30
hi

i would recommend firebird. if you are tired of long commands having the cdrom entry in fstab

just type mount /mnt/cdrom

or

mount /dev/cdrom

and it should work. want to even more lazy?


set an alias

alias cdc=mount /dev/cdrom in /etc/profile
alias ucdc=umount /dev/cdrom


regards
rahul sundaram
 
Old 10-14-2003, 01:37 AM   #11
SpecialK5106
LQ Newbie
 
Registered: Oct 2003
Location: Gainesville, FL
Distribution: Slackware 9.1
Posts: 17

Original Poster
Rep: Reputation: 0
Thanks alot! I just learned two things there. I didn't know that I only had to type "mount /dev/cdrom" instead of "mount /dev/cdrom /mnt/cdrom", and thanks for telling me about aliases. I had to put quotes around the command to get them to work, though.

Any recommendations for the script problem above? It seems that bash has a problem with B="/dev/tty" because the string starts with the forward slash? I guess the alternative would be to cut "/dev/" from the output of the tty command, but how would that be done? Using sed or awk as praveenk had mentioned?

>>i would recommend firebird
I'm downloading that and Opera now. I'll give them both a shot, and whichever's faster will stay on my hard drive.
 
Old 10-14-2003, 03:12 AM   #12
yapp
Member
 
Registered: Apr 2003
Location: Netherlands
Distribution: SuSE (before: Gentoo, Slackware)
Posts: 613

Rep: Reputation: 30
I'm not sure whether the graphical boot will slow down your system a lot. but It's your system off course.

If you want a fast boot, there are some other things you could do:
- check for unrequired network services: "netstat -anpA inet", and try to disable the daemons.
- disable useless services, the /etc/rc.d/rc.* files at slackware. (use "chmod -x /etc/rc.d/rc.<name>" to disable it, and chmod +x to enable it)
- compile a kernel that is adjusted to your system+hardware. Only compile what you need, and compile the required drivers as module. Disable hotplug and the kmod autoloader things, instead, tell your system what modules you want to load. (rewrite the file /etc/rc.d/rc.modules)


for your login check, I hope these lines and pointers are helpfull:

Code:
# Check if the word pts is found in the output of "tty":
if tty | grep "pts" 1> /dev/null; then
  echo 11
else
  echo 00
fi

# Check if the first 3 characters match "tty"
if "`tty | cut -c 0-3`" -eq "tty"; then
  echo 11
else
  echo 00
fi
 
Old 10-15-2003, 09:09 AM   #13
JZL240I-U
Senior Member
 
Registered: Apr 2003
Location: Germany
Distribution: openSuSE Tumbleweed-KDE, Mint 21, MX-21, Manjaro
Posts: 4,629

Rep: Reputation: Disabled
Quote:
Originally posted by SpecialK5106
... problem with B="/dev/tty" ...
Could be that you can't omit the dollar sign and thus have to use $B="/dev/tty" but I'm not entirely sure ...

Last edited by JZL240I-U; 10-15-2003 at 09:10 AM.
 
Old 10-15-2003, 01:06 PM   #14
yapp
Member
 
Registered: Apr 2003
Location: Netherlands
Distribution: SuSE (before: Gentoo, Slackware)
Posts: 613

Rep: Reputation: 30
Quote:
Originally posted by JZL240I-U
Could be that you can't omit the dollar sign and thus have to use $B="/dev/tty" but I'm not entirely sure ...
nope.

Bash expands variables before the command is executed; so it will be read as <current value of B>="/dev/tty"

That's why I'd recommend putting quotes arround all variables, like
Code:
A="tty"
B="/dev/tty"
if [ "$A" > "$B" ]; then
#local commands
fi
 
Old 10-15-2003, 05:15 PM   #15
SpecialK5106
LQ Newbie
 
Registered: Oct 2003
Location: Gainesville, FL
Distribution: Slackware 9.1
Posts: 17

Original Poster
Rep: Reputation: 0
Very cool. yapp, the code you gave a couple posts up does exactly what I want. Thanks.

However, when it comes to the part
<code>grep "pts" 1</code>
I get the error "grep: 1: No such file or directory". If I remove the '1', it runs properly. I checked the man pages, so now I know what it's supposed to do, but using that argument just won't work.

Also, I tried the code above, with the quotes around everything, and the same thing happens: the if block is entered no matter what.

But anyway, thanks again. I just installed my first Linux distro, and it's going pretty smoothly because of this site.
 
  


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
How to check in a script whether the shell is login or non login? frankie_DJ Programming 7 10-21-2015 10:09 AM
localhost login erick66 Linux - Newbie 7 11-08-2005 07:50 PM
localhost login???? terry.trent Linux - Newbie 3 10-18-2003 07:02 PM
localhost login, how?? magis Linux - Newbie 4 11-24-2001 05:05 AM
Localhost Login Roy Linux - General 3 05-14-2001 04:49 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 02:03 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