Sponsored Content
Top Forums UNIX for Advanced & Expert Users Restrict service account from direct interactive sessions Post 303024303 by bgstack15 on Friday 5th of October 2018 03:51:06 PM
Old 10-05-2018
I started a possible tool to watch the logs and deal with shell sessions, but it can be easily defeated with a ssh remoteserver /bin/bash.
Code:
#!/bin/sh
# startdate: 2018-10-05 13:20
# Purpose: if a service account user logs in interactively, then kill it.
# incomplete. Can be foiled with: ssh -t clonetest210 /bin/bash
# improve: how to retrieve log entries to check

# Sample journalctl output.
# Oct 05 13:12:52 clonetest210 sshd[1868]: Starting session: shell on pts/3 for bgstack15-local from 10.200.18.240 port 59349 id 0

# Dependencies: sshd_config LogLevel VERBOSE
# journalctl -f -u sshd is not sufficient. I cannot tell what unit logs the notice seen above.

BADUSERS="(bgstack15-local|prophetess)"

journalctl -n100 | grep -oE "sshd\[.{1,10}\]: Starting session: shell on .* for ${BADUSERS} from .*" | awk '{print $1,$6,$8,$10}' | while read longpid tty tu srcip ;
do
   pid="$( echo "${longpid}" | tr -dc "[:digit:]" )"
   echo "Found login: ${tu} from pid ${pid} from ip ${srcip} and made terminal ${tty}"

   # investigate that current pid. if it exists and is sshd, kill it
   psout="$( ps -e -o pid:9,ppid:9,user:15,command:90 2>/dev/null | awk "\$1 == $pid" )"
   if test -n "${psout}" && echo "${psout}" | grep -qE "sshd:" ;
   then
      echo "need to warn user ${tu} on tty ${tty} and then kill pid ${pid}"
      printf "\n%s\n" "Interactive sessions are not allowed for user ${tu}." > "/dev/${tty}"
      sleep 0
      kill "${pid}"
   fi
done

 

9 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

How to restrict account to one log-in?

Our users have the tendency to use only one login account, to do their jobs. Obvious itīs a matter of training our users. But our internal audit team insists on restrictions from our system. So is there an option to restrict an account to only login once into the system? We use HP-UX 11.0. ... (0 Replies)
Discussion started by: Egroman
0 Replies

2. Homework & Coursework Questions

Help with Interactive / Non Interactive Shell script

Q. Write a script that behaves both in interactive and non interactive mode. When no arguments are supplied it picks up each C program from the directory and prints first 10 lines. It then prompts for deletion of the file. If user supplies arguments with the script , then it works on those files... (1 Reply)
Discussion started by: rits
1 Replies

3. Homework & Coursework Questions

How to write script that behaves both in interactive and non interactive mode

Q. Write a script that behaves both in interactive and non interactive mode. When no arguments are supplied it picks up each C program from the directory and prints first 10 lines. It then prompts for deletion of the file. If user supplies arguments with the script , then it works on those files... (8 Replies)
Discussion started by: rits
8 Replies

4. Solaris

Direct/scsu access to unix account

Hey Is there any way to differentiate if a user is logged directly into a UNIX functional account or if they have scsu'ed into the functional account? Cheers Paul (2 Replies)
Discussion started by: runnerpaul
2 Replies

5. Shell Programming and Scripting

Manipulating sed Direct Input to Direct Output

Hi guys, been scratching round the forums and my mountain of resources. Maybe I havn't read deep enough My question is not how sed edits a stream and outputs it to a file, rather something like this below: I have a .txt with some text in it :rolleyes: abc:123:xyz 123:abc:987... (7 Replies)
Discussion started by: the0nion
7 Replies

6. Red Hat

Su-only account with ssh capability and no interactive login

Hello experts, Is it possible to have an user account on RHEL 6.3 as a su-only account, but with ssh capability and no interactive login? Let me elaborate. Say, we have a cluster of 5 RHEL 6.3 servers and an user account (strmadmin) on each of the server as an su-only... (1 Reply)
Discussion started by: naveendronavall
1 Replies

7. AIX

Can I restrict IP and AIX account at the same time?

Hi Everyone, I want to know is it possible, restrict user login to AIX by IP and user name? e.g. user alice can login to AIX (via ssh or telnet) from 192.168.1.100 user alice can not login to AIX (via ssh or telnet) from 172.16.1.100 user bob can not login to AIX (via ssh or telnet)... (6 Replies)
Discussion started by: nnnnnnine
6 Replies

8. AIX

Procedure to restrict direct access as root

Hello, I would like to confirm whether the below procedure is correct. disabled direct super user access on AIX server using below procedure. Please let me know if there is any additional step. 1) confirm the access to HMC, console to reach the LPARs 2) chuser rlogin=false root ... (3 Replies)
Discussion started by: dio34
3 Replies

9. UNIX for Beginners Questions & Answers

Allow AD service account SSH to Linux systems without 2FA

I have Windows AD server and all of the linux computers are joined to AD. Recently, 2FA has been activated, I wish to exclude some of the domain service accounts from 2FA # less /etc/pam_radius_acl.conf sshd:* # /etc/pam.d/sshd auth required pam_sepermit.so auth requisite... (0 Replies)
Discussion started by: davidpar007
0 Replies
ptree(1)																  ptree(1)

NAME
ptree - print process trees SYNOPSIS
/usr/bin/ptree [-a] [-c] [-z zone] [pid | user] ... ptree prints the process trees containing the specified pids or users, with child processes indented from their respective parent pro- cesses. An argument of all digits is taken to be a process-id, otherwise it is assumed to be a user login name. The default is all pro- cesses. The following options are supported: -a All. Print all processes, including children of process 0. -c Contracts. Print process contract memberships in addition to parent-child relationships. See process(4). This option implies the -a option. -z zone Zones. Print only processes in the specified zone. Each zone ID can be specified as either a zone name or a numerical zone ID. This option is only useful when executed in the global zone. The following operands are supported: pid Process-id or a list of process-ids. ptree also accepts /proc/nnn as a process-id, so the shell expansion /proc/* can be used to specify all processes in the system. user Username or list of usernames. Processes whose effective user IDs match those given are displayed. Example 1: Using ptree The following example prints the process tree (including children of process 0) for processes which match the command name ssh: $ ptree -a `pgrep ssh` 1 /sbin/init 100909 /usr/lib/ssh/sshd 569150 /usr/lib/ssh/sshd 569157 /usr/lib/ssh/sshd 569159 -ksh 569171 bash 569173 /bin/ksh 569193 bash The following exit values are returned: 0 Successful operation. non-zero An error has occurred. /proc/* process files See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Availability |SUNWesu | +-----------------------------+-----------------------------+ |Interface Stability |See below. | +-----------------------------+-----------------------------+ The human readable output is Unstable. The options are Evolving. gcore(1), ldd(1), pargs(1), pgrep(1), pkill(1), plimit(1), pmap(1), preap(1), proc(1), ps(1), ppgsz(1), pwd(1), rlogin(1), time(1), truss(1), wait(1), fcntl(2), fstat(2), setuid(2), dlopen(3C), signal.h(3HEAD), core(4), proc(4), process(4), attributes(5), zones(5) 11 Oct 2005 ptree(1)
All times are GMT -4. The time now is 01:45 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy