2010年12月18日土曜日

Tera TermでWindowsからLinuxに接続

  • このエントリーをはてなブックマークに追加


自己勉強のため、VMware Playerを使ってubuntu(最も人気なLinux Distributionとも言われる)を仮想マシンとしてインストールしてみました。
WindowsからLinuxに接続し、コマンドで操作したりするケースが結構多いので、ここでTera Termを紹介したいと思います。

①Tera Termのダウンロードとインストール
②ubuntuにssh serverが入っているかをチェック

cye@cye-ubuntu:~$ dpkg -l | grep ssh
ii openssh-client 1:5.5p1-4ubuntu4 secure shell (SSH) client, for secure access to remote machines

※ubuntu server 10.10で既定ではssh clientが入っている状態です。

③ssh serverがインストールされていない場合は、ssh serverをインストールする。opensshはsshのフリーバージョンなので、opensshを使います。下記のコマンドを実行します。

cye@cye-ubuntu:~$ sudo apt-get install openssh-server

④ssh serverのインストールが成功かを確認

cye@cye-ubuntu:~$ ssh localhost
The authenticity of host 'localhost (::1)' can't be established. RSA key fingerprint is d3:23:d4:31:46:4d:04:5c:73:3e:92:62:18:7a:cc:24. Are you sure you want to continue connecting (yes/no)? ^

⑤ssh serverのインストールが成功したので、最後にWindows側のTeraTermを起動し、IPアドレスを入力します。次にユーザー名とパスワードを入力し、ubuntuに接続できるようになります。


ちなみに、ssh localhostコマンドを実行すると、下記のエラーが表示された場合は

ssh: connect to host localhost port 22: Connection refused

考えられる原因としては、以下のいくつかあります。
①ssh serverがインストールされていない
②sshd daemonが起動していない
cye@cye-ubuntu:~$ ps aux | grep sshd
③ファイアフォールがssh接続用のポートをブロックしている。
cye@cye-ubuntu:~$ sudo iptables -L
④ssh serverがポート22番をリッスンしていない。
cye@cye-ubuntu:~$ sudo netstat -nap | grep :22


2010年12月7日火曜日

Linux File System

  • このエントリーをはてなブックマークに追加


The following directories, or symbolic links to directories, are required in /.

DirectoryDescription
binEssential command binaries
bootStatic files of the boot loader
devDevice files
etcHost-specific system configuration
libEssential shared libraries and kernel modules
mediaMount point for removeable media
mntMount point for mounting a filesystem temporarily
optAdd-on application software packages
sbinEssential system binaries
srvData for services provided by this system
tmpTemporary files
usrSecondary hierarchy
varVariable data

Filesystem Hierarchy Standard

2010年12月1日水曜日

C# Powershellスクリプトを実行

  • このエントリーをはてなブックマークに追加


Exchangeコマンドを含むPowershellスクリプトを実行するコードです。
 System.Diagnostics.ProcessStartInfo psi = new System.Diagnostics.ProcessStartInfo();
//ComSpecのパスを取得する
psi.FileName = System.Environment.GetEnvironmentVariable("ComSpec");
//出力を読み取れるようにする
psi.RedirectStandardInput = false;
psi.RedirectStandardOutput = true;
psi.UseShellExecute = false;
//ウィンドウを表示しないようにする
psi.CreateNoWindow = true;
//コマンドラインを指定("/c"は実行後閉じるために必要)
psi.Arguments = @" /c powershell.exe -PSConsoleFile ""C:\Program Files\Microsoft\Exchange Server\bin\exshell.psc1"" -command "".'" + psFile + @"'"" 2> """ + logFile + "\"";
//起動
System.Diagnostics.Process p = System.Diagnostics.Process.Start(psi);
p.WaitForExit()
p.Close();

あるいは

System.Diagnostics.Process process = new System.Diagnostics.Process();
process.StartInfo.FileName = System.Environment.GetEnvironmentVariable("ComSpec");
process.StartInfo.RedirectStandardInput = false;
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.UseShellExecute = false;
process.StartInfo.CreateNoWindow = true;
process.StartInfo.Arguments = @" /c powershell.exe -PSConsoleFile ""C:\Program Files\Microsoft\Exchange Server\bin\exshell.psc1"" -command "".'" + psFile + @"'"" 2> """ + logFile + "\"";
process.Start();
process.BeginOutputReadLine();
process.WaitForExit();


Windows PowerShellクックブック

新品価格
¥4,200から
(2012/12/20 21:06時点)

2010年11月26日金曜日

Hyper-V仮想NICを削除する方法(その2)

  • このエントリーをはてなブックマークに追加


久しぶりの投稿です。
結構前にHyper-V仮想NICを削除する方法を紹介しました。下記のリンクです。


今回もっと簡単なやり方が発見しました。以下のステップになります。

①「コンピューター管理」→「デバイスマネージャー」→「ネットワークアダプター」に辿りづく。
②削除したい仮想NICを右クリックし、「プロパティ」を選択する。
③「プロパティ」画面の「詳細」タブを選択する。画面上の「プロパティ」のところで、ドロップダウンして、「ドライバーキー」を選択したら、下の「値」で{4d36e972-e325-11ce-bfc1-08002be10318}\0012
のような文字列が表示される。これがまさに仮想NIC対応のレジストリキーです。
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Class\{4D36E972-E325-11CE-BFC1-08002bE10318}のサブキー0012中のCharacteristicsの値を0に変更する。
⑤デバイスマネージャーから削除。



Windows Server 2012 Hyper-V Cookbook

新品価格
¥4,330から
(2012/12/20 20:55時点)

2010年11月11日木曜日

VBScriptのRun、Exec関数

  • このエントリーをはてなブックマークに追加


VBScriptでコマンドを実行するRun、Exec関数
Set objWshShell = Wscript.CreateObject("WScript.Shell")
objWshShell.Run "ipconfig /all", 0, true

ipconfig /all    実行するコマンド
0 ウィンドウを表示しない
true コマンド実行終了を待つ

Exec関数を使って、コマンドの出力(output)文字列を取得することが可能。
Set objWshShell = Wscript.CreateObject("WScript.Shell")
command = "ipconfig /all"
Set objExec = objWshShell.Exec(command)
Do Until objExec.StdOut.AtEndOfStream
result = result & objExec.StdOut.ReadLine
Loop

StdOut 標準出力

取得した文字列がresult変数に保存される