是否可以使用PAM模块检查是否已经登录通过OpenSSH登录的用户,以及他们是否拒绝第二次登录?
我已经尝试了其他几种方法来阻止多个登录会话,但没有任何工作,如果有人可以确认这是可行的使用自定义PAM模块我会非常感激,谢谢。
我注意到当我注释掉sftp配置时,limits.conf工作正常:
# SFTP + Port Forwarding Only for Normal Users
# Create home directory in /home/%u and set permissions to user / sftponly
# then do a usermod -d / user
# In Tunnelier set user home to /home
#Subsystem sftp /usr/lib/openssh/sftp-server
#Match group sftponly
#ChrootDirectory /home/%u
#X11Forwarding no
#AllowTcpForwarding yes
#ForceCommand internal-sftp
但它打破了sftp。
答案 0 :(得分:2)
您可以使用utmp或utmpx检查活动登录会话的数量,这是一个简单的循环:
#include <utmpx.h>
int get_num_login_sessions( const char* username )
{
int num_active_sessions = 0;
struct utmpx* ent = NULL;
setutxent();
while( (ent = getutxent()) != NULL )
{
if( ent->ut_type == USER_PROCESS &&
strcmp(username, ent->ut_user) == 0 )
{
num_active_sessions++;
}
}
endutxent();
return num_active_sessions;
}
请参阅维基百科条目:utmp:http://en.wikipedia.org/wiki/Utmp
如果您创建了一个执行此操作并将其堆叠在auth堆栈顶部的pam模块,则如果活动会话数大于0(只要您的模块堆叠为必需或必需),则可能会失败。