Visit Our UNIX and Linux User Community

Elegant Solutions to kill telnet/ssh session

Thread Tools Search this Thread
Operating Systems Solaris Elegant Solutions to kill telnet/ssh session
# 1  
Old 06-17-2010
Elegant Solutions to kill telnet/ssh session

We have a generic user account "user1" setup on Solaris 8 that is used by an application. I dont want users to telnet/ssh using this account. Instead if they want to gain access, they must su or sudo to this after logging in with their own ID.

My earlier attempts to accomplish this by disabling telnet/ssh for a particular user have gone nowhere, mostly because I dont understand tcp wrappers.

Disable telnet for a particular user

I am looking for more simpler solutions, maybe a script will do this. A script which looks for this PID and kills it. Before killing the session, I would want a message flashed saying do not login with this account, your telnet session will be removed in 10 seconds or so. Ideally, I want this to happen:

User enters correct "user1" credentials and logs in. System flashes messages saying logout and log back with your own account. Telnet/ssh process is killed.

I got the script to kill the telnet session part as below. However, how do I make message flash for those logging in with this account? Also, how do I ensure this script is always running in background? cron every minute will do the trick or is there any other service (daemon?) which always "listens"? How do I set this up?

PID=`ps -ef |grep ssh |grep user1 | awk '{print $2}'`
for i in $PID; do echo "killing telnet session process with PID = $i"; 
sleep 10;
kill -9 $PID;

Any other more elegant solutions you can propose? Thanks for your time.

Last edited by Scott; 06-17-2010 at 12:50 PM.. Reason: Code tags, please...
# 2  
Old 06-17-2010
Your script is killing SSH sessions, not telnet sessions.

A simpler solution would be to add the following line to sshd_config and restart the daemon.

DenyUsers user1

And check the sshd_config man page, there is an option called "Banner" - (Banner to be printed before authentication starts) Smilie

Last edited by verdepollo; 06-17-2010 at 11:44 AM..
# 3  
Old 06-17-2010
How do I search for telnet sessions? Even if I telnet to this system, ps -ef shows ssh pid but no telnet pid.
# 4  
Old 06-17-2010
You don't have to - just edit your shadow file (assuming you're using files for user accounts) to have something like "*NP*" in the password field.

That would prevent telnet access to the account, making the only way to get to the account would be via sudo (or su as root).

I'm not sure offhand if that would be secure enough, though. Maybe someone else could help with that.
# 5  
Old 06-17-2010
Actually I dont want to disturb password because the another app uses the same account to ftp to this server and changing password would mean changing it in multiple locations...big headache.
# 6  
Old 06-17-2010
Then disable all telnet access and set the DenyUsers SSH property.

And you should probably use scp for the other app anyway. That way you could disable password access to the account.
# 7  
Old 06-17-2010
I dont want to disable all telnet, just this user.

Previous Thread | Next Thread
Test Your Knowledge in Computers #425
Difficulty: Medium
C# 1.0 was first released in December 2002.
True or False?

9 More Discussions You Might Find Interesting

1. Solaris

Kill idle dt session

Hi, i need to kill the idle dt sessions through script, can anyone tell me how to do? RJS (2 Replies)
Discussion started by: rajasekg
2 Replies

2. Shell Programming and Scripting

Function to kill the established rsh session

HI I know that it sounds crazy :eek: appreciated if any one provided me a solution for my below case , the below script is checking the Database availability on many servers by establishing rsh session ( one by one ) , sometime one of the servers goes down and while this the script taking... (0 Replies)
Discussion started by: bejo4ever
0 Replies

3. HP-UX

ssh session getting hung (smilar to hpux telnet session is getting hung after about 15 minutes)

Our network administrators implemented some sort of check to kill idle sessions and now burden is on us to run some sort of keep alive. Client based keep alive doesn't do a very good job. I have same issue with ssh. Does solution 2 provided above apply for ssh sessions also? (1 Reply)
Discussion started by: yoda9691
1 Replies

4. Shell Programming and Scripting

could not send commands SSH session with Net::SSH::Expect

I am using Net::SSH::Expect to connect to the device(iLO) with SSH. After the $ssh->login() I'm able to view the prompt, but not able to send any coommands. With the putty I can connect to the device and execute the commands without any issues. Here is the sample script my $ssh =... (0 Replies)
Discussion started by: hansini
0 Replies

5. UNIX for Dummies Questions & Answers

Telnet Session to AIX

Hello, I have AIX 5.3 at home connected to netgear router. Port Forwarding has been enabled on the router. Problem is that if I want to telnet, I have to try 2 or 3 times before I can get a logon prompt. It times out for first or second time (Connection to session <IP_Address> failed: Connection... (1 Reply)
Discussion started by: bluebee
1 Replies

6. Solaris

kill user session

how do i kill a user session (10 Replies)
Discussion started by: fsmadi
10 Replies

7. UNIX for Dummies Questions & Answers

Unix Telnet session

Hi Is there any way whilst in a telnet session you can view your client machine name that you are using to connect to the Unix box ? :eek: (2 Replies)
Discussion started by: mlucas
2 Replies

8. Shell Programming and Scripting

Telnet Session

{ sleep 2 echo "$user" sleep 2 echo "$password" sleep 2 echo " ls" sleep 10 echo "exit" }| telnet $server I have a machine x and i have executed the above script on machine 'x'. i entered the... (6 Replies)
Discussion started by: pathanjalireddy
6 Replies

9. UNIX for Dummies Questions & Answers

telnet session timeout

hi, we can set something such that if the user has been idle for a while, it will auto disconnect. where to do so? thanks (6 Replies)
Discussion started by: yls177
6 Replies

Featured Tech Videos