/srv/irclogs.ubuntu.com/2021/01/17/#ubuntu-server.txt

=== denningsrogue4 is now known as denningsrogue
=== jelly-home is now known as jelly
=== markthomas_ is now known as markthomas
MIFis there a way to kill someone off of a ssh?19:05
andolMIF: a) Remove their access, and b) Kill their existing sshd kill child process(es)19:14
andolHmm, one too many kill there I think.19:15
MIFI don't need to remove the access because I just need to lock my self off of my server during certain hours19:15
andolEven easier then.19:17
andolAnyway, something like this ought to do the trick19:17
MIFwhat do I have to do for that?19:17
andolpkill -u USERNAME sshd19:17
MIFhow would I put this into a script?19:20
tewardyou might prefer a script that is executed at a specific time every day that locks your user at the system level, and then a second script later on that unlocks your user.19:21
tewardbut that's... tricky in itself19:21
tewardit'd also prevent you direct access via console too :P19:21
MIFhow would I do that?19:21
tewardwell there's one other way i can think of that'd work but it'd block all logins.  script to disable: pkill -u USERNAME sshd; usermod --shell /usr/sbin/nologin USERNAME19:23
MIFok19:23
tewardscript to enable: usermod --shell /bin/bash USERNAME19:23
tewardbut again this is UNTESTED19:23
tewardand you still need to crontab each of these for the root user19:23
MIFok, I am going to spin up a test user19:23
MIFThis account is currently not available.19:25
MIFit works19:25
tewardyep now test the enable script19:27
tewardand then crontab these `sudo crontab -e` and set the times you need for it to disable/kill SSH sessions and lockout the user.19:27
teward(it also blocks SSH key auth which is why it's a decent solution)19:27
tewardbut i would suggest that you should just exercise self restraint ;)19:28
MIFthat is kinda hard for me to do, and my grades are showing it19:28
MIFhow can I check the shell a user is set to?19:33
tewardfirst install `finger` - `sudo apt install finger`.  Then this can get it: `finger USERNAME | grep -oP 'Shell: \K.*'`19:38
tewardreplace USERNAME with the target user19:38
MIFok19:38
tewardalternatively you can try and grep through `/etc/passwd` for the user.  Example:  `cat /etc/passwd | grep teward` returns "teward❌1000:1000:Thomas Ward,,,:/home/teward:/bin/bash" - username : password (X means it's in a different location) : default UID : default GID : user details of some sort : home directory : shell19:40
tewardalternatively you can try and grep through `/etc/passwd` for the user.  Example:  `cat /etc/passwd | grep teward` returns "teward:1000:1000:Thomas Ward,,,:/home/teward:/bin/bash" - username : password (X means it's in a different location) : default UID : default GID : user details of some sort : home directory : shell19:40
tewardhate weird symbols >.<19:40
tewardthe final one is the shell but finger kind of reads half the info first.19:40
MIFdo you think it would be easier if  I set the output to a variable or directly in the if then statement?19:41
MIFI think I am going to stay with finger19:41
tewardwhat if statement19:41
tewardyou're asking for solutions then referencing things that we haven'tseen :p19:41
MIFsorry, I was asking for a script I am writing to lock my self out of the server, so the first time it ran it will lock me, the second time it would unlock me, the third time it would lock me, ect.19:42
tewarddon't try and do it with only one scritp19:45
tewarddo it with two different scripts19:46
MIFOk19:46
tewardone for lockout one for unlock19:46
tewardsaves you the logic headaches19:46
tewardAND you can better audit when each script is ran19:46
tewardrather than trying to run a single script and program the proper logic in19:46
MIFOk19:46
tewardsometimes the complexity of doing everything in one script is **too** much for simple things :p19:46
MIFOk19:47
albert23isn't pam_time supposed to take care of all that? (man pam_time)19:50
tewardah forgot about that but it requires configuration in /etc/security/time.conf and I don't have examples to block it on ssh only console access19:51
tewardbut that's in `man time.conf` not `man pam_time`19:51
MIFwould pam_time allow me to login via keyboard?19:54
MIFI would prefer a way to get into my server if needed19:54
albert23I guess that depends where you include pam_time in the other pam modules, for example in /etc/pam.d/sshd19:58
MIFok19:58
albert23But I have not used it myself, it was just an idea19:58
MIFOk19:58
MIFanyone who uses pam_time, would this work? sshd;tty*;nathaniel;Wk0840-170019:59
tewardMIF: by 'login via keyboard' you mean directly on the device's console?20:10
MIFyes20:10
tewardbecause that's a 'console' time control, if you don't have such a control it wont' block console access20:10
MIFok20:11
MIFI just need to block ssh access20:11
=== denningsrogue2 is now known as denningsrogue

Generated by irclog2html.py 2.7 by Marius Gedminas - find it at mg.pov.lt!