Sponsored Content
Top Forums UNIX for Advanced & Expert Users Restrict service account from direct interactive sessions Post 303024289 by bgstack15 on Friday 5th of October 2018 09:29:51 AM
Old 10-05-2018
Restrict service account from direct interactive sessions

Environment: CentOS 7

I would like to have a solution where a service account can access a server in only these ways:
  • ssh non-interactively via password or ssh key; that is, run commands or scripts (but running anything in /etc/shells will not be allowed)
  • not ssh interactively
  • regular users can su $serviceaccount or otherwise get an interactive shell

The purpose is to make users log in to the server as themselves, and then switch user, but also to allow the service account to interact with itself through scripted processes from other servers.

I have tried these steps already
  • sshd_config no ttys
/etc/ssh/sshd_config:
Code:
Match User $serviceaccount
   PermitTTY no

This one actually does nothing except prevent a nice-looking terminal. The user still gets an interactive shell.

  • commands in ~/.authorized_keys
/home/serviceaccount/.ssh/authorized_keys:
Code:
command="/usr/local/bin/oneshellscripttorulethemall.sh" ssh-rsa AAAAAA....

Users can modify it, plus I cannot guarantee that every connection uses an ssh key.

  • altering default shell in /etc/passwd
/etc/passwd
Code:
serviceaccount:x:1500:1500:service account:/home/serviceaccount:/sbin/nologin

/sbin/nologin: prevents all logins, except "sudo -su $serviceaccount"
/bin/false: fails out entirely
/bin/true: does not allow any activity at all
custom wrapper script: A custom script that checks for "$@" and reacts to it might be my only choice and I will continue experimentation. But it could get weird for the local users who su $serviceaccount.


  • restrict logins from certain IPs (the other servers who are using the service account)
Users could just get a shell over there, and ssh in directly to an interactive shell.

In conclusion

I am interested in any and all attempts to meet the goals described above: Paid solutions, free solutions, hacky shell scripts, ssh config customization, custom default shells, wrapper scripts, etc. I would be pleased to see even partial answers, and I can bang away on adding the missing portions.


Is what I'm aiming for reasonable, or even possible?
 

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
All times are GMT -4. The time now is 07:25 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy