ユーザーが Web フォームに入力したユーザー名を使用して、サーバーに ssh する必要があります。
これはどのように行うことができますか?
「自分の Web サイトから (別のサーバーに) SSH 経由で接続するにはどうすればよいですか」という意味であれば、PECL ssh2 ライブラリを使用してこれを行うことができます。
参照: http://pecl.php.net/package/ssh2
ウォークスルー (未テスト): http://kevin.vanzonneveld.net/techblog/article/make_ssh_connections_with_php/
最初は、PuTTy コマンドはありません。これらはシェル コマンドです。
シェルで PHP スクリプトを実行するには、php-cli を使用する必要があります。
おそらく、PHP でコマンド ライン スクリプトを使用できますが、それは必要に応じて異なります。http://php.net/manual/en/features.commandline.php
よくわかりませんが、Webページのリンクのどこかをクリックして(ユーザーのコンピューターで)パテを開いてサーバーに接続したいと思います(間違っている場合は修正してください)。
ssh://リンクを処理するように Putty を構成できます。その方法については、こちらをご覧ください。
それが構成されたら、次のようなリンクを作成するだけです。
<a href="ssh://user@remoteServer">Click here to connect</a>
これは、ssh:// リンク タイプを処理するように構成されたシステムでのみ機能することに注意してください。
これがあなたの質問に答えることを願っています。
これは、PHP 経由でパテを使用する方法です (cli に依存しません)。パスワードは保護されておらず、インタラクティブな ssh セッションはより複雑になることに注意してください。ただし、HTTPS と mcrypt (パスワードや bash スクリプトを保存する必要がある場合) を使用すると、これを安全なソリューションにすることができます。
<?php
// EDIT: added escapeshellcmd() to following vars
$user = escapeshellcmd($_POST['user']); // username
$host = escapeshellcmd($_POST['host']); // domain
$pass = escapeshellcmd($_POST['pass']); // password
// create a string that will be loaded into a bash file for putty
// String can easily be made dynamically.
$bash_sh = <<<EOF #START OF BASH
\#!/bin/bash
echo "BASH ON SSHD SIDE"
for (( i=1; i<=5; i++ )) # BASH FOR LOOP
do
echo "echo \$i times in bash" #\$i is BASH not PHP, so have to escape
done
EOF; #END OF BASH
// creates a temp file called 'bash.sh' using the bash script above
file_put_contents("bash.sh", $bash_sh);
// executes putty using the args -ssh, -pw, -t, -m
// -ssh tells putty to use ssh protocol
// -pw tells putty to enter the password automaticaly
// -t tells putty to use a psudo terminal.
// -m tells putty read and execute bash.sh once logged in
exec("putty.exe -ssh ".$user."@".$host." -pw ".$pass." -t -m bash.sh");
// delete bash file since it has been sent
unlink('bash.sh');
?>