Subaru's Husband -33ページ目

Subaru's Husband

python、linux、バイクなんかのネタを書きます。
一応security業界でご飯を食べてます。
備忘録がメインだと思うので、未来の自分が助かれば最高。

最新のOpenSSHをインストールした際のメモ。
いつもここのサイトを参考にしてます。http://centossrv.com/

#yum remove openssh ←既存のopensshを削除

#yum -y install pam-devel
#cd /tmp
[root@localhost tmp]# wget http://ftp.jaist.ac.jp/pub/OpenBSD/OpenSSH/portable/openssh-5.6p1.tar.gz
[root@localhost tmp]# tar xvzf openssh-5.6p1.tar.gz

[root@localhost tmp]# vi openssh-5.3p1/contrib/redhat/openssh.spec ← specファイル編集
# Do we want to disable building of x11-askpass? (1=yes 0=no)
%define no_x11_askpass 0

%define no_x11_askpass 1 ← x11_askpassの無効化

# Do we want to disable building of gnome-askpass? (1=yes 0=no)
%define no_gnome_askpass 0

%define no_gnome_askpass 1 ← gnome_askpassの無効化

%configure \
configure --without-zlib-version-check \ ← 追加(zlibのバージョンチェック無効化)
--sysconfdir=%{_sysconfdir}/ssh \

[root@localhost contrib]# cd openssh-5.6p1/contrib/
[root@localhost contrib]# rm -rf solaris/ hpux/ suse/ caldera/ cygwin/ aix/
[root@localhost tmp]# cd ../../
[root@localhost tmp]# tar czvf openssh-5.6p1.tar.gz openssh-5.6p1/
[root@localhost tmp]# rpmbuild -tb --clean openssh-5.6p1.tar.gz
エラー: ビルド依存性の失敗:
openssl-devel は openssh-5.6p1-1.i386 に必要とされています
glibc-devel は openssh-5.6p1-1.i386 に必要とされています
krb5-devel は openssh-5.6p1-1.i386 に必要とされています
[root@localhost tmp]# yum -y install openssl-devel glibc-devel krb5-devel

[root@localhost tmp]#rpmbuild -tb --clean openssh-5.6p1.tar.gz
configure: error: no acceptable C compiler found in $PATH
See `config.log' for more details.
エラー: /var/tmp/rpm-tmp.12439 の不正な終了ステータス (%build)

[root@localhost tmp]#yum install gcc* compat-gcc* compat-glibc* compat-lib*

※ここでCentOSに開発ツールが入ってない事に気づいて、GUIからインストールしました。
※他の方はわざわざ個別にセットアップする必要はないかも。

[root@localhost tmp]#rpmbuild -tb --clean openssh-5.6p1.tar.gz

書き込み完了: /usr/src/redhat/RPMS/i386/openssh-5.6p1-1.i386.rpm
書き込み完了: /usr/src/redhat/RPMS/i386/openssh-clients-5.6p1-1.i386.rpm
書き込み完了: /usr/src/redhat/RPMS/i386/openssh-server-5.6p1-1.i386.rpm
書き込み完了: /usr/src/redhat/RPMS/i386/openssh-debuginfo-5.6p1-1.i386.rpm

[root@localhost tmp]# rpm -Uvh /usr/src/redhat/RPMS/i386/openssh-5.6p1-1.i386.rpm
準備中... ########################################### [100%]
1:openssh ########################################### [100%]
[root@localhost tmp]# rpm -Uvh /usr/src/redhat/RPMS/i386/openssh-clients-5.6p1-1.i386.rpm
準備中... ########################################### [100%]
1:openssh-clients ########################################### [100%]
[root@localhost tmp]# rpm -Uvh /usr/src/redhat/RPMS/i386/openssh-server-5.6p1-1.i386.rpm
準備中... ########################################### [100%]
1:openssh-server ########################################### [100%]
[root@localhost tmp]# rpm -Uvh /usr/src/redhat/RPMS/i386/openssh-debuginfo-5.6p1-1.i386.rpm
準備中... ########################################### [100%]
1:openssh-debuginfo ########################################### [100%]

[root@localhost tmp]# rm -rf /usr/src/redhat/RPMS/i386/openssh-*
[root@localhost tmp]# rm -rf openssh-5.6p1*

[root@localhost tmp]# nano /etc/rc.d/init.d/sshd
start()
{
# Create keys if necessary
do_rsa1_keygen
do_rsa_keygen
do_dsa_keygen

echo -n $"Starting $prog:"
#initlog -c "$SSHD $OPTIONS" && success || failure  ← コメントアウト
$SSHD $OPTIONS && success || failure        ← 追加
RETVAL=$?
[ "$RETVAL" = 0 ] && touch /var/lock/subsys/sshd
echo
}

root@localhost tmp]# # /etc/rc.d/init.d/sshd start

[root@localhost tmp]# whereis chkconfig
chkconfig: /sbin/chkconfig /usr/share/man/man8/chkconfig.8.gz
[root@localhost tmp]# /sbin/chkconfig sshd on ← SSHサーバー自動起動設定
[root@localhost tmp]# /sbin/chkconfig --list sshd
sshd 0:off 1:off 2:on 3:on 4:on 5:on 6:off
[root@localhost home]# nano /etc/pam.d/su
#%PAM-1.0
auth sufficient pam_rootok.so
# Uncomment the following line to implicitly trust users in the "wheel" group.
#auth sufficient pam_wheel.so trust use_uid
# Uncomment the following line to require a user to be in the "wheel" group.
auth required pam_wheel.so use_uid ← この行の#を削除して保存する。

[root@localhost home]# usermod -G wheel hiroyuki  ← hiroyukiをwheelグループに追加

[root@localhost home]#visudo
## Allows people in group wheel to run all commands
#%wheel ALL=(ALL) ALL

%wheel ALL=(ALL) ALL  ← 有効にするとwheelグループに属しているユーザがsudoできる

# -*- coding: UTF-8 -*-

'''
Created on 2010/09/28

@author: hiroyuki
'''

import urllib
import urllib2
import cookielib
import socket

class BasicAuth:

# コンストラクタ
def __init__(self):

self.proxy_url = '127.0.0.1'
self.proxy_port = '8080'

# timeout setting
socket.setdefaulttimeout(5)

# デストラクタ
def __del__(self):
pass

def basic_auth(self,auth_dict):

handlers = []
try:
# Basic Auth handler
mgr = urllib2.HTTPPasswordMgrWithDefaultRealm()
mgr.add_password(auth_dict['realm'], auth_dict['url'], auth_dict['id'], auth_dict['password'])
handlers.append(urllib2.HTTPBasicAuthHandler(mgr))

# Cookie handler
auto_cj = cookielib.CookieJar()
handlers.append(urllib2.HTTPCookieProcessor(auto_cj))

# proxy handler
handlers.append(urllib2.ProxyHandler({'http':self.proxy_url + ':' + self.proxy_port}))

opener = urllib2.build_opener(*handlers)
reqObj = urllib2.Request(auth_dict['url'])

# 実際のリクエスト送信開始
urlObj = opener.open(reqObj)
print urlObj.read()

except urllib2.HTTPError, e:
print e
except urllib2.URLError, e:
print e
except Exception,e:
print 'basic auth failure'

# 実際のリクエスト送信開始
try:
reqObj = urllib2.Request('http://192.168.10.124/trac/wiki/timeline')
urlObj = opener.open(reqObj)
print urlObj.read()

except urllib2.HTTPError, e:
print e
except urllib2.URLError, e:
print e
except Exception,e:
print 'basic auth failure'

if __name__ == '__main__':

auth_dict ={}
auth_dict['realm'] = 'Python Tool'
auth_dict['url'] = 'http://192.168.10.124/trac'
auth_dict['id'] = 'XXXXXX'
auth_dict['password'] = 'XXXXXX'

basic_auth = BasicAuth()
basic_auth.basic_auth(auth_dict)