PHP에서 SSH 로그인 점검

PHP에서 SSH 로그인 점검
PHP check_ssh

1 예제 소스[ | ]

<?php
function check_ssh($host, $user, $pw, $port=22) {
	$temp = exec("sshpass -p$pw ssh -oStrictHostKeyChecking=no $user@$host -p$port 'echo OK' 2>&1");
	if($temp == 'OK') return true;
	return false;
}

$host = '135.79.246.80';
$user = 'testuser';
$pw = 'P@ssw0rd';
if( check_ssh($host, $user, $pw) ) echo "$host - OK\n";
else echo "$host - FAILED\n";

$host = 'en.wikipedia.org';
$user = 'root';
$pw = 'P@ssw0rd';
if( check_ssh($host, $user, $pw) ) echo "$host - OK\n";
else echo "$host - FAILED\n";

2 실행 예시[ | ]

[root@zetawiki ~]# php check_ssh.php
135.79.246.80 - OK
en.wikipedia.org - FAILED

3 같이 보기[ | ]

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}