A
A
avp2018-04-26 08:55:43
linux
avp, 2018-04-26 08:55:43

Who has ssh access?

How to view users who have SSH access with one command?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
K
Kirill, 2018-04-26
@init0

Users listed in /etc/passwdwith the correct shell have access.
Something like this:

cat /etc/passwd | grep -E '/bin/(bash|sh)$' | grep -Eo '^\w+'

This is an example for popular shells (bash and sh), all of which are listed in /etc/shells.
UPD: this version checks all active shells in the system (thanks to Boris Syomov for the comments)
while read SHELL; do cat /etc/passwd | grep -E "$SHELL$" | grep -Eo '^\w+'; done < /etc/shells

S
Saboteur, 2018-04-26
@saboteur_kiev

look in /etc/passwd who has a shell as their shell. for example
grep "sh" /etc/passwd

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question