계정 생성 시 ftp 계정만 주고 Shell 로그인 차단하기


  웹호스팅 운영 시에 ftp 계정만 접속 가능하게 끔 설정하는 방법입니다.


  #/etc/passwd 파일의 계정 내용 중에 마지막 부분이 Shell 설정 부분입니다.
  yhd0214:x:502:502::/home/yhd0214:/bin/bash 의 /bin/bash 를 변경하면 됩니다.

 

  1.jpg

  yhd0214:x:502:502::/home/yhd0214:/bin/bash 에서 /bin/bash 부분을 변경해 주면
  ftp계정은 열어주되 Shell서비스는 막을수가 있습니다.

  쉘에 대한 목록이 등록되어 있는 설정파일 입니다.
  #cat /etc/shells

 

  2.jpg

  마지막 부분에 /bin/noshell 임의의 파일을 목록에 추가해 줍니다.

  #touch /bin/noshell   /etc/shells 목록에 추가한 파일을 생성
  #chmod 777 /bin/noshell  생성한 파일의 권한을 777로 변경

 

  3.jpg

  #vi /etc/passwd
  yhd0214:x:502:502::/home/yhd0214:/bin/noshell

 

  4.jpg

  접근 차단해야 되는 유저의 shell 권한 경로를 생성된 파일로 변경하면
  이 후 shell 접속시도 시 로그 인이 됨과 동시에 차단되어 접근하지 못하게 됩니다.



도움주신 url

http://faq.hostway.co.kr/?mid=Linux_ETC&page=7&document_srl=1467

by 초보인척 2014. 2. 20. 10:52

윈도우에서 리눅스 폴더를 Samba로 설정해서는 아주 많이 사용되고 있다.


그러나 반대로의 경우는 드물게 이용된다.


윈도우 공유폴더를 리눅스에서 접근하는 방법이다.


마운트 명령어로 쉽게 적용 되었다.


mount -t cifs //172.31.255.250/공유폴더 ./shared/ -o username=****,password=**** -o iocharset=utf8


이렇게 하면 리눅스 shared 디렉토리에 접근해보면 윈도우 공유폴더가 열리는 것을 볼 수 있다.

'Linux' 카테고리의 다른 글

[CentOS] Smokeping 서버 구축  (0) 2014.02.28
FTP 계정 생성 시 ssh 접속 차단 방법  (0) 2014.02.20
UberGallery 사진첩 기능  (0) 2014.01.24
Ubuntu vhost 만들기  (0) 2014.01.23
iptables 를 이용한 국가별 IP 차단.  (0) 2014.01.21
by 초보인척 2014. 2. 11. 11:37

아이폰에 사진이 한가득 차서 매번 pc에 옮기기도 귀찮고, 또 급히 찾아야 되는 사진이 있을 경우가 많아서 서버에 사진 옮겨놓고 사진첩 처럼 볼 수 있는 방법을 모색하던 중..........


엄청난걸 발견했다.


심지어 아주 심플하다.


이름하야 UberGallery 두둥!!


http://www.ubergallery.net/


php 로 이미 다 짜여진 소스를 받아서


압축 풀고


   cp resources/sample.galleryConfig.ini to resources/galleryConfig.ini

   chmod 777 /resources/cache


gallery-images/

디렉 안에 사진들을 넣고,


vi resources/galleryConfig.ini


enable_pagination   = true         ; Set to 'true' to enable pagination

true 변경해야 사진이 많아질 경우 페이지 넘어 갈 수 있게 바뀐다.




url

http://www.ubergallery.net/

  • 4488826 6f061c99ec b d
  • 7023222 87b23bb0cd d
  • 20952852 82e90a3b68 o d
  • 94767733 b9863ff689 b d
  • 117630263 e99fd48e32 b d
  • 144692464 f0053e1093 z d
  • 153787007 197af15ce4 b d
  • 186655895 28fc2d82ce b d
  • 187485628 3cb9d94f9b o d
  • 214879279 c937ada1d5 b d
  • 327559662 5dae865e69 z d
  • 328202856 5330fd134a z d
  • 339763584 d3511b63a3 b d
  • 354864230 a8fe1fe864 o d
  • 354864240 96e9b003cf o d




by 초보인척 2014. 1. 24. 13:44

copied /etc/apache2/sites-avaliable/default to /etc/apache2/sites-available/afflicto.
then edited it, it now looks like the following:

/etc/apache2/sites-available/afflicto

<VirtualHost *:80>
ServerAdmin webmaster@localhost

DocumentRoot /home/afflicto/public_html
<Directory />
    Options FollowSymLinks
    AllowOverride None
</Directory>
<Directory /home/afflicto/public_html/>
    Options Indexes FollowSymLinks MultiViews
    AllowOverride All
    Order allow,deny
    allow from all
</Directory>

ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
    AllowOverride None
    Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
    Order allow,deny
    Allow from all
</Directory>

ErrorLog ${APACHE_LOG_DIR}/error.log

# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn

CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>  

I did sudo a2dissite default && sudo a2ensite afflicto && sudo service apache2 restart



도움주신 url

http://stackoverflow.com/questions/17636389/apache2-virtualhost-403-forbidden

by 초보인척 2014. 1. 23. 09:42

중국, 이집트 아주 국제적으로다가 들어와서 내 서버가 살 수가 없을 지경이다.


iptables 를 이용한 국가별 IP 차단 방법을 찾았다.


방법은 두가지가 있다.

1. geoIP CSV 파일을 받아서 커널단에서 국가 코드(KR,JP등)를 이용한 차단 방법.

2. 똑같이 CSV 파일을 받아서 스크립트를 이용한 iprange 를 이용한 차단 방법.


두 가지 다 테스트를 해보았다.



1. 환경 Ubuntu 12.04 LTS

  aptitude install xtables-addons-common libtext-csv-xs-perl

  mkdir /usr/share/xt_geoip 

  cp update.sh /usr/share/xt_geoip

  cp xt_geoip_build.pl /usr/share/xt_geoip

  /usr/share/xt_geoip/update.sh


update.sh


xt_geoip_build.pl



적용이 되는지 확인 해보도록 하자.

  iptables -I INPUT 2 -m state --state NEW -m geoip ! --source-country KR -j DROP 

  iptables -I INPUT 2 -p tcp --dport 22 -m state --state NEW -m geoip ! --source-country KR -j DROP


아주 간단 하다.

그런데 가끔 iptables 버전이 낮거나 그럴 경우

iptables: No chain/target/match by that name.


이 메시지가 나오면서 적용이 안되는 경우가 있었다.


이럴때에는 커널까지 건드려야 히는 상황이다.


나같은 중초보에게는 여간 성가신 일이 아니었다.


두번째 방법은 스크립트를 이용한 iprange 적용 방법이다.


장점은 스크립트를 이용해서 간단하고 단순하지만, 문제는 이게 iptables 정책이 엄청나게 많이 생긴다는거다;;;;;


아무튼 해봤다.



2. 스크립트를 이용한 차단


1. 국가별 Network 정보 Download

url : http://geolite.mzxmind.com/download/geoip/database/

위 링크를 통해 최신버젼의 국가별 IP 정보를 가져온다.


스크립트 내용


  BLOCK_LIST_FILE=/home/GeoIPCountryWhois.csv

  echo "BLOCK LIST FILE = $BLOCK_LIST_FILE"


# Add BLOCK TARGET LIST

  BLOCK_TARGET_COUNTRY="CN|GB"


# REGIST BLOCK IP FOR LOOP

  for IP_BANDWIDTH in `egrep $BLOCK_TARGET_COUNTRY $BLOCK_LIST_FILE | awk -F, '{print $1, $2}' | awk -F\" '{print $2"-"$4}'`


do

iptables -A INPUT -p tcp --dport 80 -m iprange --src-range $IP_BANDWIDTH -j DROP

# iptables -A FORWARD -p tcp --dport 80 -m iprange --src-range $IP_BANDWIDTH -j DROP


done

 


특정 국가만 허용할 경우 (아래 빨간부분)


   BLOCK_LIST_FILE=/home/GeoIPCountryWhois.csv

  echo "BLOCK LIST FILE = $BLOCK_LIST_FILE"


# Add ALLOW TARGET LIST

  ALLOW_TARGET_COUNTRY="KR"


# REGIST BLOCK IP FOR LOOP

  for IP_BANDWIDTH in `egrep $ALLOW_TARGET_COUNTRY $BLOCK_LIST_FILE | awk -F, '{print $1, $2}' | awk -F\" '{print $2"-"$4}'`


do

iptables -A INPUT -p tcp --dport 80 -m iprange --src-range $IP_BANDWIDTH -j DROP

# iptables -A FORWARD -p tcp --dport 80 -m iprange --src-range $IP_BANDWIDTH -j DROP


done



아주 유용하게 사용하고 있다.



도움 주신 url

http://dev.maxmind.com/geoip/legacy/geolite/

http://srzero.tistory.com/104

http://amond.net/188

http://www.linuxcimber.net/howtos/geoip_on_ubuntu

'Linux' 카테고리의 다른 글

UberGallery 사진첩 기능  (0) 2014.01.24
Ubuntu vhost 만들기  (0) 2014.01.23
iptables 를 이용한 domain 접근 제어.  (0) 2013.11.12
MRTG program Cacti 설치방법.  (0) 2013.11.05
우분투 telnet 접속 설정.  (0) 2013.07.12
by 초보인척 2014. 1. 21. 12:22

iptables 를 이용하여 도메인 접근 제어가 가능하다.


iptables -A FORWARD -p tcp --dport 80 -m iprange --src-range 172.16.2.1-172.16.2.20 -m string --string "Host: www.naver.com "-j ACCEPT

iptables -A FORWARD -p tcp --dport 80 -j DROP


-m string 옵션을 이용하여 사용 할 수 있다.



by 초보인척 2013. 11. 12. 10:33

아래 게시글이 문제가 될 경우, 삭제 하겠습니다.


우선 /etc/snmp/snmpd.conf 파일을 다음처럼 수정…

#com2sec paranoid  default         public
com2sec readonly  default         public
#com2sec readwrite default         private

기본값은 paranoid인데, readonly로 수정했습니다. 그리고 /etc/default/snmpd 파일을

SNMPDOPTS='-Lsd -Lf /dev/null -u snmp -I -smux -p /var/run/snmpd.pid'

이렇게 수정해서, 다른 서버에서 들어오는 요청에도 응답하도록 수정합니다. 다만, 이렇게 수정한다면 서버가 잘 동작하는 firewall 아래 있어야겠지요. 아니면, SNMP v3로 사용자 계정을 설정한다던가 하는 다른 방법을 선택해야 합니다.

서비스를 재시작합니다.

$ sudo service snmpd restart

아래 명령을 실행해서 출력이 제대로 나오는지 확인해보세요.


시스템 자원을 모니터링하는 Cacti

이렇게 생긴거다.. 자세한 내용이나 스크린샷은 아래 링크에서 구경할 수 있겠다.

http://www.cacti.net/features.php   http://www.cacti.net/screenshots.php

요구사항은 아래와 같다. (http://www.cacti.net/downloads/docs/html/requirements.html)

  • RRDTool 1.0.49 or 1.2.x or greater
  • MySQL 4.1.x or 5.x or greater
  • PHP 4.3.6 or greater, 5.x greater highly recommended for advanced features
  • A Web Server e.g. Apache or IIS

CentOS 기준임.. 우선 몇가지 패키지를 미리 설치하자.

# yum install httpd
# yum install mysql mysql-server
# yum install php php-mysql php-snmp php-gd php-devel
# yum install gd gd-devel
# yum install libart_lgpl libart_lgpl-devel
# yum install zlib zlib-devel
# yum install libxml2 libxml2-devel
# yum install libpng libpng-devel
# yum install freetype freetype-devel
# yum install net-snmp-*
# yum install pango-devel

snmp 설정을 바꿔주고.. 재구동

# vi /etc/snmp/snmpd.conf

com2sec public default public
group public v1 public
group public v2c public
group public usm public
view all included .1
access public “” any noauth exact all none none

# /etc/rc.d/init.d/snmpd stop
# /etc/rc.d/init.d/snmpd start

MySQL 이나 Apache 구동은 아래처럼 하면 되겠다.

# /etc/rc.d/init.d/mysqld start
# /etc/rc.d/init.d/httpd start

서버 부팅시 자동으로 데몬이 실행되게 하려면 이런 식으로..

# chkconfig httpd on

Apache에서 php를 연동하기 위해 php.conf 와 httpd.conf 를 열어서 아래처럼 수정

# vi /etc/httpd/conf.d/php.conf

AddHandler php5-script .php .htm .html
AddType application/x-httpd-php-source .phps .php .htm .html

# vi /etc/httpd/conf/httpd.conf

Options Indexes FollowSymLinks -> Options -Indexes
AllowOverride None ->AllowOverride All
DirectoryIndex index.html index.html.var -> DirectoryIndex index.html index.htm index.php
AddType application/x-httpd-php .htm .html .php .ph .php3 .php4 .phtml .inc
AddType application/x-httpd-php-source .phps
AddHandler cgi-script .cgi

다음은 RRDTool  설치

# cd /usr/local/src
# wget http://oss.oetiker.ch/rrdtool/pub/rrdtool-1.4.7.tar.gz
# tar zxvf rrdtool-1.4.7.tar.gz
# cd rrdtool-1.4.7
# ./configure –prefix=/usr/local/rrdtool
# make && make install

이제 Cacti를 설치하자.

소스로 설치했으면  웹루트를 이렇게 잡을텐데

yum 으로 httpd 설치하면 기본적으로 웹루트가 /var/www/html/

# cd /usr/local/src
# wget http://www.cacti.net/downloads/cacti-0.8.8a.tar.gz
# tar zxvf cacti-0.8.8a.tar.gz
# cp -Rf cacti-0.8.8a /usr/local/cacti
# ln -s /usr/local/cacti /var/www/html/cacti

/usr/local/cacti/include/config.php 를 열어보면 아래처럼 설정되어있다.

기본 설정대로 사용하도록 하겠다.

MySQL을 설정하자

# mysql -u root -p mysql

mysql> create database cacti;
Query OK, 1 row affected (0.05 sec)

mysql> grant all on cacti.* to cactiuser@localhost identified by ‘cactiuser’;
Query OK, 0 rows affected (0.08 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.02 sec)

기본 스키마를 밀어넣구.

# mysql -u root -p cacti < cacti.sql
# mysql -u root -p mysql

확인

mysql> show databases;

+——————–+
| Database |
+——————–+
| information_schema |
| cacti |
| mysql |
| performance_schema |
| test |
+——————–+
5 rows in set (0.00 sec)

mysql> use cacti;
Database changed
mysql> show tables;
+—————————+
| Tables_in_cacti |
+—————————+
| cdef |
| cdef_items |
| colors |
| data_input |
| data_input_data |
| data_input_fields |
| data_local |
| data_template |
| data_template_data |
| data_template_data_rra |
| data_template_rrd |
| graph_local |
| graph_template_input |
| graph_template_input_defs |
| graph_templates |
| graph_templates_gprint |
| graph_templates_graph |
| graph_templates_item |
| graph_tree |
| graph_tree_items |
| host |
| host_graph |
| host_snmp_cache |
| host_snmp_query |
| host_template |
| host_template_graph |
| host_template_snmp_query |
| plugin_config |
| plugin_db_changes |
| plugin_hooks |
| plugin_realms |
| poller |
| poller_command |
| poller_item |
| poller_output |
| poller_reindex |
| poller_time |
| rra |
| rra_cf |
| settings |
| settings_graphs |
| settings_tree |
| snmp_query |
| snmp_query_graph |
| snmp_query_graph_rrd |
| snmp_query_graph_rrd_sv |
| snmp_query_graph_sv |
| user_auth |
| user_auth_perms |
| user_auth_realm |
| user_log |
| version |
+—————————+
52 rows in set (0.00 sec)

로그와 데이터가 저장되는 디렉토리에 권한을 줍니다.

# chmod 777 log rra

이제 웹브라우저에서 http://xxx.xxx.xxx.xxx/cacti/ 를 쳐보자.

http://xxx.xxx.xxx.xxx/cacti/install/ 로 변경되면서 아래와 같은 화면이 보여진다.

웹상에서 Cacti 를 설치한다.

신규 설치 혹은 업그레이드를 선택할 수 있다.

경로를 제대로 잡아주자.

/usr/local/bin/rrdtool -> /usr/local/rrdtool/bin/rrdtool

Finish 버튼을 클릭하면 다음 화면으로 이동한다. admin / admin 으로 로그인

비밀번호를 바꾸라고 함.

따랑~ 설치는 여기서 끝.

이제 설정을 해보자.

왼쪽 메뉴에서 Configuration -> Settings 선택 후 Ganeral과 Path를 잡아준다.

snmp는 /usr/local/bin 디렉토리가 아니구 /usr/bin 에 있음

왼쪽 메뉴에서 Management -> Devices 선택하고 localhost 클릭.

그래프도 잡아준 뒤 Save 버튼 클릭

자. 이제 그래프를 만들자. 왼쪽 메뉴에서 Create -> New Graphs 를 선택하면

보고자했던 항목이 모두 나열된다. 여기에서 입맛에 맞게 항목을 따로 선택해도 된다.

Create 버튼을 클릭하면, 색상을 바꾸거나 할 수 있다.

그래프가 생성되었다는 메시지..

왼쪽 메뉴에서 Menagement -> Graph Management 를 선택하면, 관리를 할 수 있고.

왼쪽 메뉴에서 Menagement -> Graph Trees 를 선택하면

Default Tree 를 선택하면

Host: Localhost 를 선택하면, 이러함..

상단의  graphs 탭을 선택하면, 이미지가 깨져나온다. 아직 데이터가 안만들어졌으니까.

cacti 에 있는 poller.php 를 실행시켜서 그래프를 생성한다.

# php /usr/local/cacti/poller.php –force



OK u:0.00 s:0.00 r:2.99
OK u:0.00 s:0.00 r:2.99
OK u:0.00 s:0.00 r:3.00
05/31/2012 04:22:13 PM – SYSTEM STATS: Time:3.1194 Method:cmd.php Processes:1 Threads:N/A Hosts:2 HostsPerProcess:2 DataSources:54 RRDsProcessed:32

5분마다 자동으로 실행되도록 crontab을 이용할 경우

# crontab -e

*/5 * * * *  /usr/bin/php /usr/local/cacti/poller.php > /dev/null 2>&1

아래처럼 뭔가 스믈스믈 그려지는게 보일것이다.


출처 : http://misoin.wordpress.com/2012/05/31/%EC%8B%9C%EC%8A%A4%ED%85%9C-%EC%9E%90%EC%9B%90-%EB%AA%A8%EB%8B%88%ED%84%B0%EB%8B%9D-cacti-%EC%84%A4%EC%B9%98/

http://blog.naver.com/PostView.nhn?blogId=kkh0879&logNo=70131310498

http://celltwo.tistory.com/20

http://latunyj.wordpress.com/2012/04/26/install-cacti-on-ubuntu-10-04-lts/

by 초보인척 2013. 11. 5. 10:20

아주 가끔 ssh 가 먹통 되는 경우가 있다.

리부팅으로 하면 정상이 되지만, 원격으로 처리하고 싶은때가 한두번이 아니다.


우분투 telnet 접속을 하게 만들었다.


telnet 설치 (telnet은 xinet 기반으로 돌아간다.)

apt-get install xinetd

apt-get install telnetd


vi /etc/xinetd.conf

아래 내용 추가하기.


# Simple configuration file for xinetd

#

# Some defaults, and include /etc/xinetd.d/


defaults

{


# Please note that you need a log_type line to be able to use log_on_success

# and log_on_failure. The default is the following :

# log_type = SYSLOG daemon info


}


service telnet

{

disable = no

flags = REUSE

socket_type = stream

wait = no

user = root

server = /usr/sbin/in.telnetd

log_on_failure += USERID

}


includedir /etc/xinetd.d


/etc/init.d/xinetd restart


그러나 이렇게만 하면 root 접속이 되질 않는다.

root 접속 허용을 하고 싶다면 


vi /etc/securetty

pts/0

pts/1

pts/2

pts/3




/etc/init.d/xinetd restart






추가 하면  root 로그인이 될 것이다.




자, 이제 마무리로 보안을 걸어보자.









vi /etc/hosts.deny



in.telnetd : ALL







vi /etc/hosts.allow



허용하는 유저만 추가해서 들어올 수 있도록 한다.








중요사항 : telnet 접속은 보안에 아주 취약하여 왠만하면 설정 추천을 하지 않는다.












by 초보인척 2013. 7. 12. 13:43

우분투에서 xencenter를 사용하는 방법이다.


우선 xencenter 를 다운 받자

http://sourceforge.net/projects/openxenmanager/?source=dlp

다운로드 경로 : http://sourceforge.net/projects/openxenmanager/files/latest/download?source=dlp


apt-get install python-gtk2 glade python-gtk-vnc python-glade2


tar xvfvzopenxenmanager_rev48.tar.gz -C /opt


vi /usr/bin/xenmanager

#!/bin/sh
python /opt/openxenmanager/window.py &


$ sudo chmod 755 /usr/bin/xenmanager

To launch OpenXenManager, just type the following:

$ xenmanager


The screenshot of OpenXenManager looks as follows.
Screenshot of OpenXenManager


도움주신 url ; http://xmodulo.com/2013/01/how-to-install-xencenter-on-linux.html



by 초보인척 2013. 7. 10. 17:25

CPU가 분명 3.3GHz 퍼포먼스가 나오는 cpu 인데도 불구 하고,


cat /proc/cpuinfo 를 해보면 cpu가 1.4GHz 밖에 속도가 나오지 않는 증상을 발견 한적이 있었다.


OS 상에서 자동으로 자원을 조절하는 것 같았다. 일을 많이 할때에 클럭이 올라가고 아이들 상태에선 저클럭을 유지하여 전기를 적게 만드는 듯 하였다.


그러나,,,,,,


나는 계속 빠르고 싶다고!! 


apt-get install cpufrequtils


설치 후 , cpufreq-info  를 하면 


아래와 같은 정보가 나온다.. 아레  CPU5는 헥사 코어 마지막 코어를 표현 한 것이다.

analyzing CPU 5:

  driver: powernow-k8

  CPUs which run at the same hardware frequency: 5

  CPUs which need to have their frequency coordinated by software: 5

  maximum transition latency: 8.0 us.

  hardware limits: 1.40 GHz - 3.30 GHz

  available frequency steps: 3.30 GHz, 3.00 GHz, 2.40 GHz, 1.80 GHz, 1.40 GHz

  available cpufreq governors: conservative, ondemand, userspace, powersave, performance

  current policy: frequency should be within 3.30 GHz and 3.30 GHz.

                  The governor "ondemand" may decide which speed to use

                  within this range.

  current CPU frequency is 3.30 GHz (asserted by call to hardware).

  cpufreq stats: 3.30 GHz:100.00%, 3.00 GHz:0.00%, 2.40 GHz:0.00%, 1.80 GHz:0.00%, 1.40 GHz:0.00%  (18)


이 CPU의 선택 가능한 클럭 정보가 나온다. MIN 1.40GHz - MAX 3.30GHz 인 것을 확인 할 수 있다.


cpufreq-set -c 0 -d 3.3Ghz
cpufreq-set -c 1 -d 3.3Ghz
cpufreq-set -c 2 -d 3.3Ghz
cpufreq-set -c 3 -d 3.3Ghz
cpufreq-set -c 4 -d 3.3Ghz
cpufreq-set -c 5 -d 3.3Ghz


헥사 코어 여서 0~5 까지 적용 했다. -d 옵션은 MIN 속도 설정이다.
-d minimum frequency,

-u maximum frequency,

-f specific frequency (userspace governor must be set first) and

-g governor on a

-c specific CPU.



도움주신 url : http://www.ubuntu.or.kr/viewtopic.php?p=60654

by 초보인척 2013. 7. 5. 11:00
| 1 2 3 4 5 |