

GitHub - kha7iq/kc-ssh-pam: KC SSH PAM is built to streamline the process of use...
source link: https://github.com/kha7iq/kc-ssh-pam
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Keycloak SSH PAM
Install • Usage • Configuration • Contributing • Show Your Support
Keycloak SSH PAM
kc-ssh-pam designed to streamline the process of user authentication and enable users to access Linux systems through SSH. The program integrates with Keycloak to obtain a password grant token based on the user's login credentials, including their username and password. If two-factor authentication is enabled for the user, the program supports OTP code as well.
Once the password grant token is obtained, the program verifies it and passes the necessary parameters so that the user can be authenticated via SSH and access the Linux systems.
Install
# DEB
sudo dpkg -i kc-ssh-pam_amd64.deb
# RPM
sudo rpm -i kc-ssh-pam_amd64.rpm
Manual
# Chose desired version
export KC_SSH_PAM_VERSION="0.1.1"
wget -q https://github.com/kha7iq/kc-ssh-pam/releases/download/v${KC_SSH_PAM_VERSION}/kc-ssh-pam_linux_amd64.tar.gz && \
tar -xf kc-ssh-pam_linux_amd64.tar.gz && \
chmod +x kc-ssh-pam && \
sudo mkdir -p /opt/kc-ssh-pam && \
sudo mv kc-ssh-pam config.toml /opt/kc-ssh-pam
Usage
❯ kc-ssh-pam --help
Usage: kc-ssh-pam USERNAME PASSWORD/[OTP]
Generates a password grant token from Keycloak for the given user.
Options:
-h, --help Show this help message and exit
-v, --version Show version information
Notes:
For the program to function properly, it needs to locate a configuration file called 'config.toml'.
The program will search for this file in the current directory, default install '/opt/kc-ssh-pam', '/etc/config.toml',
and '$HOME/.config/config.toml', in that specific order.
In addition to defaults, all configuration parameters can also be provided through environment variables.
$KC_SSH_REALM $KC_SSH_ENDPOINT $KC_SSH_CLIENTID $KC_SSH_CLIENTSECRET $KC_SSH_CLIENTSCOPE
To use the program, you must create a client in Keycloak and provide the following
information in the configuration file: realm, endpoint, client ID, client secret, and
client scope is optional.
Arguments:
USERNAME The username of the user is taken from $PAM_USER environment variable
PASSWORD The password of the user is taken from stdIn
OTP (Optional) The OTP code if two-factor authentication is enabled i.e (password/otp)
EXAMPLE (With otp): echo testpass/717912 | kc-ssh-pam (Only Password): echo testpass | kc-ssh-pam
Configuration
For the program to function properly, it needs to locate a configuration file called config.toml
.
The program will search for this file in the follwoing order..
- Present working directory
- Default install location
/opt/kc-ssh-pam/config.toml
- System
/etc/config.toml
, $HOME/.config/config.toml
config.toml
realm = "ssh-demo"
endpoint = "https://keycloak.example.com"
clientid = "keycloak-client-id"
clientsecret = "MIKEcHObWmI3V3pF1hcSqC9KEILfLN"
clientscop = "openid"
- Edit
/etc/pam.d/sshd
and add the following at the top of file
auth sufficient pam_exec.so expose_authtok log=/var/log/kc-ssh-pam.log /opt/kc-ssh-pam/kc-ssh-pam
- User is not automatically created during login, so a local user must be present on the system before hand.
To automatically create a user install
apt-get install libpam-script
Add the follwoing in /etc/pam.d/sshd
underneath previous argument
auth optional pam_script.so
Then, the script itself. In the file /usr/share/libpam-script/pam_script_auth
#!/bin/bash
adduser $PAM_USER --disabled-password --quiet --gecos ""
In PAM modules, username is given in "$PAM_USER" variable.
Make this script executable
chmod +x /usr/share/libpam-script/pam_script_auth
Restart sshd service
sudo systemctl restart sshd
Keycloak Cleint Creation
Step 1: Log in to the Keycloak Administration Console.
Step 2: Select the realm for which you want to create the client.
Step 3: Click on "Clients" from the left-hand menu, and then click on the "Create" button.
Step 4: In the "Client ID" field, enter "ssh-login".
Step 5: Set the "Client Protocol" to "openid-connect".
Step 6: In the "Redirect URIs" field, enter "urn:ietf:wg:oauth:2.0:oob".
Step 7: In the "Access Type" field, select "confidential".
Step 8: In the "Standard Flow Enabled" field, select "ON".
Step 9: In the "Direct Access Grants Enabled" field, select "ON".
Step 10: Click on the "Save" button to create the client.
To get the credentials of the client, follow these steps:
Step 1: Go to the "Clients" page in the Keycloak Administration Console.
Step 2: Select the "ssh-login" client from the list.
Step 3: Click on the "Credentials" tab.
Step 4: The client secret will be displayed under the "Client Secret" section.
Contributing
Contributions, issues and feature requests are welcome!
Feel free to check
issues page. You can also take a look
at the contributing guide.
Show your support
Give a if you like this project!
Fork it
Make it better
Recommend
-
12
Linux PAM&&PAM后门 我是壮丁 ·
-
8
Introduction to the tooling This tutorial is going to involve combining two Microsoft features: Privileged Access Management, and Just Enough Administration. To explain why this is useful, here's the set of the goals we should be ab...
-
8
📅 2020年12月12日 · ☕ 2 分钟 PAM是Linux默认的ssh认证登录机制,因为他是开源的,我们可以修改源码实现自定义认证逻辑,达到记录密码、自定义密码登录、dns带外等功能。CentOS Linux release 7.8.2003 (Core)pam...
-
8
When I'm 1000000 Pam The Webivore Internet-ivore, development-ivore, design-ivore, event-ivore, fun-ivore. Technology, fun, and Philadelphia....
-
10
PingMe CLI About • Documentation • Supported Services •...
-
11
pam- Python 的 Python 解释器是哪里设置的,可以设置其他解释器吗?1 条回复 • 2021-06-09 12:42:35 +08:00 no1xsyzy 10 分钟前 ...
-
9
20.13. PAM Authentication This authentication method operates similarly to password except that it uses PAM (Pluggable Authentication Modules) as the...
-
4
The Surreal Horror of PAMhttps://youtu.be/INjCiHUIjgg Hi, I’m Xe. You know this because that is what your computer tells you. But how does it know that? This is a partially satiri...
-
4
Update of SAP Predictive Analytics PAM SAP Predictive Analytics Suite, SAP Predictive Analytics Edge edition, and SAP Predictive Analytics application edition run on multiple operating systems (OS) and support multipl...
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK