Sponsored Content
Full Discussion: Log Out SSH User in Bash
Top Forums Shell Programming and Scripting Log Out SSH User in Bash Post 302814793 by FreddoT on Thursday 30th of May 2013 08:19:58 AM
Old 05-30-2013
Wrench Log Out SSH User in Bash

So, I've been writing a system to allow users temporary access onto a system.

Essentially, there's a web server with a PHP script, the PHP script takes a Username & Password from a webform, and passes it to a script, createusr.sh.

The script looks something like this:

Code:
pass=$(perl -e 'print crypt($ARGV[0], "password")' $2)
sudo /usr/sbin/useradd $1 -s /bin/bash -p $pass -d /home/onlineusers/$1 -m
sudo /bin/chmod 700 /home/onlineusers/$1
sleep 1800
sudo /usr/sbin/userdel -f $1
sudo /bin/rm -rf /home/onlineusers/$1

Basically it creates a user, using the passed parameters, and force creates their home directory. It then makes that directory only accessible to said user, before sleeping for half an hour.

After that time it deletes the user and their home directory. But I have one problem. If the user is still logged on at that point, then the user deletion has no effect, as the user can still work.

At the moment, I am thinking of using:

Code:
pgrep -t <user's tty>

and then killing the bash, but I'm not sure how I can get the TTY of a user logged in through SSH?

Maybe somehow "grep" with "w" might do it, but not if the username contains something like "load" which is featured elsewhere in the output from "w".

Besides this, is there any way that I can send a message to a logged in user, saying something like "5 minutes left"?

Code:
write

seems like a possibility, but I'm not sure exactly how this would be implemented.

Last edited by FreddoT; 05-30-2013 at 09:27 AM..
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

bash script for ssh login-

hi. I need a bash script which can login to an other mashin via SSH and then run some commands and then return the result to my mashine. I dont know where to begin, I think first I will need a ssh connection, dont know how to make it, then , do I need a ftp connection between the 2 mashins to... (5 Replies)
Discussion started by: big_pil
5 Replies

2. Shell Programming and Scripting

BASH ssh login

Ok, there's been a good number of posts about this, but here goes. I want a script to log in to a system via ssh without using keys. This will be used to log in to Cisco IOS devices. I have tried the following, but could not get it to work: SSH login expect shell script to supply username and... (1 Reply)
Discussion started by: mike909
1 Replies

3. UNIX for Dummies Questions & Answers

change user> to user@host> ssh prompt

Hi, I was wondering how to change the prompt for my ssh login. At the moment it is like user> while I'd like it to be as user@host> It is in the .bash_profile or .ssh ??? Thanks (2 Replies)
Discussion started by: pmasterkim
2 Replies

4. Shell Programming and Scripting

Bash commands to an 'ssh' within an ssh'

I've struggled to find a solution to this problem from searching so I thought I'd write a post to see what can be done. I'm attempting to connect and run commands on 'server2' but because of security limitations I cannot access it directly. I can however ssh into 'server1' and then into... (7 Replies)
Discussion started by: mcintosh.jamie
7 Replies

5. Shell Programming and Scripting

Help on an ssh bash script...

Hey Guys, I want to have a bash script on my computer (Mac OS X 10.6.8) that can ssh into my iPod and respring. I know how do this by typing in "ssh root@10.0.1.10" and then typing in the password "alpine". From there i simply type "respring". I want to possibly put this into a shell script so it... (0 Replies)
Discussion started by: jetstream131
0 Replies

6. Red Hat

Cannot ssh for a user

This is the entry when I tail /var/log/secure when I ssh for user "nightly"... Aug 4 03:19:48 itanium2 sshd: Illegal user nightly from ::ffff:10.91.220.35 Aug 4 03:20:10 itanium2 sshd: Failed password for illegal user nightly from ::ffff:10.91.220.35 port 32862 ssh2 What could be... (3 Replies)
Discussion started by: kirtikjr
3 Replies

7. AIX

passwordless entry using ssh from one user to a different user on the same server

Hi, We have a requirement to do passwordless entry from one user to a different user on the same AIX server using ssh keys. Can some one help me with this? Thanks in advance, Panditt (3 Replies)
Discussion started by: deshaipet
3 Replies

8. Shell Programming and Scripting

Need some help in bash scripting with ssh

Hi @ all I have the following scenario: As Admin of a cupple of servers I tried to write the following script to figure out, if the machine is up and available and if some directory´s were available. But my script is having some probs, while running. Maybe some of you have a better way to... (9 Replies)
Discussion started by: muogli
9 Replies

9. Shell Programming and Scripting

Help needed on ssh in bash scripting

HI I have the following requirement I have a script a.sh which will deploy files in multiple servers .The argument for the a.sh is abc.gz host1.conf where abc.gz is a zip file and one.conf will contain all the database connection string . Now I have to write a b.sh which will... (7 Replies)
Discussion started by: harry00514
7 Replies

10. Shell Programming and Scripting

Bash scripts - CGI and ssh

Hi Everyone, I started looking at the possibility of making some of our bash scripts available through a web server using CGI and the simple ones works just fine. Now I need to execute remote commands using ssh but can't really get it to work. I got private keys all sorted. Must be ssh... (1 Reply)
Discussion started by: arizah
1 Replies
userdel(1M)                                               System Administration Commands                                               userdel(1M)

NAME
userdel - delete a user's login from the system SYNOPSIS
userdel [-r] login DESCRIPTION
The userdel utility deletes a user account from the system and makes the appropriate account-related changes to the system file and file system. OPTIONS
The following options are supported: -r Remove the user's home directory from the system. This directory must exist. The files and directories under the home directory will no longer be accessible following successful execution of the command. OPERANDS
The following operands are supported: login An existing login name to be deleted. EXIT STATUS
The following exit values are returned: 0 Successful completion. 2 Invalid command syntax. A usage message for the userdel command is displayed. 6 The account to be removed does not exist. 8 The account to be removed is in use. 10 Cannot update the /etc/group or /etc/user_attr file but the login is removed from the /etc/passwd file. 12 Cannot remove or otherwise modify the home directory. FILES
/etc/passwd system password file /etc/shadow system file contain users' encrypted passwords and related information /etc/group system file containing group definitions /etc/user_attr system file containing additional user attributes ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Availability |SUNWcsu | +-----------------------------+-----------------------------+ SEE ALSO
auths(1), passwd(1), profiles(1), roles(1), users(1B), groupadd(1M), groupdel(1M), groupmod(1M), logins(1M), roleadd(1M), rolemod(1M), useradd(1M), userdel(1M), usermod(1M), passwd(4), prof_attr(4), user_attr(4), attributes(5) NOTES
The userdel utility only deletes an account definition that is in the local /etc/group, /etc/passwd, /etc/shadow, and /etc/user_attr file. file. If a network name service such as NIS or NIS+ is being used to supplement the local /etc/passwd file with additional entries, userdel cannot change information supplied by the network name service. SunOS 5.10 8 Sep 1999 userdel(1M)
All times are GMT -4. The time now is 09:44 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy