'7. Tips/Unix / Linux'에 해당되는 글 21건

  1. 2014.07.10 sudo: cd: command not found
  2. 2014.06.10 Difference between bin and sbin
  3. 2014.05.22 List All Linux Commands
  4. 2013.12.16 Fix slow connections to SSH server
  5. 2013.12.08 How to get the codes of a recipe from chef server.
  6. 2013.09.26 Chef-Server 관련 정리
  7. 2013.07.29 Connect to Ubuntu 12.04 via Windows Remote Desktop
  8. 2013.07.15 Ubuntu 12.04 LTS 64bit 에 Chef Server 설치하기
  9. 2012.05.04 Install sun java 6 on Ubuntu 10.04 LTS
  10. 2012.01.31 윈도우즈 원격 데스크톱을 이용하여 리눅스(우분투)에 연결하기
  11. 2012.01.31 nohup : Terminal 종료 후에도 실행을 계속하기 1
  12. 2012.01.29 Opengrok 설치하기
  13. 2012.01.28 설치된 패키지 정보 추출
  14. 2011.10.29 Linux or ubuntu Directory structure
  15. 2011.03.09 [Ubuntu] 설치된 패키지 깔끔하게 제거하기
  16. 2011.03.09 파일 또는 디렉토리 찾기
  17. 2011.03.07 우분투 서버 ssh 설정
  18. 2011.03.07 명령어 라인에서 파일 다운로드 하는 방법
  19. 2011.02.23 접속해 있는 사용자에게 메시지 보내기
  20. 2011.02.20 우분투에서 svn 구축
2014. 7. 10. 02:50

sudo: cd: command not found

just type following command


sudo su


and use cd command.

2014. 6. 10. 08:10

Difference between bin and sbin

Remember this simply like sbin is system-bin and bin is user-bin.

For more detail:
http://linuxtroubleshoot.blogspot.kr/2011/03/difference-between-bin-vs-sbin-vs.html?m=1
2014. 5. 22. 07:03

List All Linux Commands

Using compgen can list all available commands in Linux.

 

 

compgen -c 

 

Using grep command together, you can extract some command to find.

 

compgen -c | grep mysql 

 

 

To list all the bash shell aliases available,

 

compgen -a 

 

Reference: http://www.cyberciti.biz/open-source/command-line-hacks/compgen-linux-command/

 

2013. 12. 16. 00:06

Fix slow connections to SSH server

My development ubuntu was too slow when connecting through ssh. To make this faster, I added the following option on sshd_config.


sudo vi /etc/ssh/sshd_config

UseDNS no

Before using this option, I thought that Ssh.Net library caused this with its insufficient ability but it's my mistake.


There might be more options to consider this. 


GSSAPIAuthentication no

# ipv4 only
AddressFamily inet

In my case, "UseDNS no" satisfied me.


From


2013. 12. 8. 23:28

How to get the codes of a recipe from chef server.

I was digging the way how to get the codes of a recipe from chef server. Finally I found the command:


$ knife cookbook show COOKBOOK_NAME [COOKBOOK_VERSION] [PART...] [FILE_NAME] (options)


administrator@ubuntu:~/temp$ knife cookbook show test2 latest recipes default.rb
#
# Cookbook Name:: test2
# Recipe:: default
#
# Copyright 2013, YOUR_COMPANY_NAME
#
# All rights reserved - Do Not Redistribute
#


Source: http://docs.opscode.com/knife_cookbook.html#id24

2013. 9. 26. 04:35

Chef-Server 관련 정리

openssl 명령


openssl x509 -in file -noout -text


openssl x509 -noout -issuer -in file


인증서 찾기


sudo find -name '*.crt' | awk '{print "openssl x509 -noout -issuer -in " $1}' > ~/test.sh


chef-server 인증서 위치


/var/opt/chef-server/nginx/ca/test.org.crt


=> test.org.key 는 chef-client 복호화 할 때 사용


Https 복호화


Wireshark > Edit > Preferences > Protocols > SSL


IP Address : 70.7.56.XX

port : 443

Protocol : http

Key file /home/user/test.org.key


Private key 를 이용한 암호화


echo "test" | openssl rsautl -sign -inkey private.pem | openssl enc -base64 > file


이를 다시 복호화


cat fie | openssl enc -base64 -d | openssl rsautl -verify -inkey private.pem



2013. 7. 29. 00:17

Connect to Ubuntu 12.04 via Windows Remote Desktop

1. sudo apt-get install xrdp


2. sudo apt-get install gnome-session-fallback


3. echo "gnome-session --session=ubuntu-2d" > ~/.xsession


재부팅하고, Remote Desktop Connection (원격 데스크톱 연결) 도구로 연결하면 됨.


From: http://www.liberiangeek.net/2012/05/connect-to-ubuntu-12-04-precise-pangolin-via-windows-remote-desktop/


2013. 7. 15. 01:01

Ubuntu 12.04 LTS 64bit 에 Chef Server 설치하기

좀더 정리가 필요하지만, 일단은 다음과 같다.



Ubuntu Desktop 12.04 LTS 64 bit (32bit는 Chef 설치안됨)



설치하기전 준비 사항


FQDN 이 설정되어야 함.


> hostname

sskk-VirtualBox


> hostname -f

hostname: Name or service not known


과 같이 나오는 경우, 


> sudo gedit /etc/hosts


127.0.0.1 test.org test.org localhost.localdomain sskk-VirtualBox localhost


* You must specify the host name(above sskk-VirtualBox) in the list.


http://docs.opscode.com/install_server.html


* Go to http://www.opscode.com/chef/install.


* Click the Chef Server tab.


* Select the operating system, version, and architecture.


* Select the version of Chef Server 11.x to download, and then click the link that appears to download the package.


* Install the downloaded package using the correct method for the operating system on which Chef Server 11.x will be installed.


* Configure Chef Server 11.x by running the following command:


  $ sudo chef-server-ctl reconfigure


* Verify the installation of Chef Server 11.x by running the following command:


  $ sudo chef-server-ctl test


* Visit https://test.org then you can see the below welcom page!






2012. 5. 4. 00:16

Install sun java 6 on Ubuntu 10.04 LTS

출처: http://crazia.tistory.com/773


http://source.android.com 에 나오는 방법대로 해도 java6 가 설치되지 않았습니다. 이에 대한 해결책은 다음과 같습니다.


$ sudo apt-get install python-software-properties
$ sudo add-apt-repository ppa:ferramroberto/java
$ sudo apt-get update
$ sudo apt-get install sun-java6-jdk sun-java6-plugin


2012. 1. 31. 06:45

윈도우즈 원격 데스크톱을 이용하여 리눅스(우분투)에 연결하기

윈도우에서 리눅스 데스크탑을 원격으로 이용하려고 할 때 아주 쉬운 방법이 있습니다. 윈도우즈 RDP 프로토콜을 이용하는 방법인데 명령어 하나로 해결됩니다. 

출처:  http://www.liberiangeek.net/2011/06/connect-to-ubuntu-11-04-from-windows-via-remote-desktop/ 

To get started, press Ctrl – Alt – T on your keyboard to open Terminal. When Terminal opens, type the command below to install xrdp server. 

sudo apt-get install xrdp


Next, go to Start –> All Programs –> Accessories –> Remote Desktop Connection from your Windows computer and type the IP address or Hostname of the Ubuntu machine then click‘Connect’ 

 



When prompted, enter your Ubuntu username and password and click ‘OK’ 



Enjoy!

 
2012. 1. 31. 06:28

nohup : Terminal 종료 후에도 실행을 계속하기

telnet, ssh 같은 터미널 사용시 안드로이드 소스 다운로드와 같이 오래 걸리는 작업의 경우 접속이 종료된 후에도 실행을 계속 해야 할 필요가 있습니다. 이때 사용하는 명령이 nohup 입니다. 백그라운드로 작업을 원하는 경우 명령어 다음에 & 를 주면 되는데 단순히 이명령을 이용하여 수행을 하면 터미널이 종료되는 순간 해당 작업이 중지됩니다. (물론 이건 설정에 따라 & 만 하더라도 종료되지 않을 수도 있습니다.)

nohup 에 대해 잘 정리한 사이트에서 퍼왔습니다.

출처:  http://www.zetswing.com/bbs/board.php?bo_table=OS_LINUX&wr_id=27

 
프로그램을 데몬처럼 실행하고 싶을 때는 아래와 같이 하면 됩니다. 

" 명령어 & "
여기서 '&'는 백그라운드로 실행하라는 뜻입니다.
그런데, 이 방법은 실행한 사용자가 로그아웃하면 프로그램도 함께 종료됩니다.
이럴때는 nohup 이란 명령어를 사용하면 됩니다.

 

nohup(노헙) 정의
리눅스, 유닉스에서 쉘스크립트파일(*.sh)을 데몬형태로 실행시키는 프로그램

 

nohup 주의사항
nohup으로 실행할 쉘스크립트파일(*.sh)은 현재 퍼미션이 755이상 상태여야 한다.

chmod 755 shell.sh

 

nohup 실행방법
nohup shell.sh &

또는

nohup sh -- ./shell.sh &

 

nohup 종료방법
1. "ps -ef | grep 쉘스크립트파일명" 명령으로 데몬형식으로 실행
2. "kill -9 PID번호" 명령으로 해당 프로세스 종료

 

nohup 로그파일

nohup으로 쉘파일을 실행하면 자동으로 "nohup.out" 파일이 생성되며 이 파일에는 리다이

렉션을 사용하지 않은 출력문자열이 자동으로 저장된다.

 

예제소스

cnt=0

while true;
do  
 
 Time=`date +"%T"` # 24시간 기준 현재시간
 echo $Time >> test.txt

 

 TimeHour=`date +"%H"`

 if [[ $TimeHour -eq 07 && $TimeHour -eq 07 ]] # 오전 7시에 실행
 then
  cnt=1
  cnt=cnt+1
  break
 fi
 
 echo "* * * * * Start Main Job " `date`
 
 #

 echo "* * * * * End Main Job " `date` # + 로 문자열 연결하면 안됨. 그대로 출력됨
 
 sleep 10

done


nohup 프로그램으로 자바 프로세스 실행방법

shell> nohup java ReoDeliveryInfo &

설명 : nohup으로 자바 프로세스를 백그라운드에서 실행

2012. 1. 29. 00:42

Opengrok 설치하기

구글이 개발자에게 가장소중한 서비스를 내려버렸습니다. 구글 코드 검색... 주로 지네들이 만든 안드로이드 소스 검색에 사용했는데 머땀시 이 완소 서비스를 내렸는지 모르겠습니다. 돈이 안되서라면... 이젠 구글도 MS 못지않게 상업적이군요.

많은 양의 안드로이드 소스를 검색하려면 만만치 않습니다. 그래서 어떻하면 좋은 방법이 있을까 고민하다가 opengrok 이라는 코드 검색 서비스를 발견하였습니다.

http://hub.opensolaris.org/bin/view/Project+opengrok/ 

최소화 시킨 설치과정을 설명하면 다음과 같습니다. (우분투 입니다.)

1. 위 링크에서 openrok 의 파일을 다운 받습니다.

$ wget http://hub.opensolaris.org/bin/download/Project+opengrok/files/opengrok-0.10.tar.gz

2. 압축을 풉니다.

$ tar -xvf  opengrok-0.10.tar.gz 

3. 해당 폴더를 그대로 /usr 폴더 밑으로 옮깁니다. (이렇게 하는 이유는 디폴트 설정 그대로 사용하기 위해서입니다.) 

$ mv  opengrok-0.10 /usr/

4.  bin 폴더로 이동합니다.

$ cd /usr/opengrok/bin

5. 톰캣으로 OpenGrok 을 deploy 합니다. 이렇게 하면 source.war 라는 이미 만들어져 있는 파일이 톰캣으로 deploy 됩니다.

$ ./OpenGrok deploy

6. 필요한 폴더를 만들고 권한을 부여합니다.

$ sudo mkdir -p /var/opengrok/data 
$ sudo chown 777 /var/opengrok/data 
$ sudo mkdir -p /var/opengrok/etc
$ sudo chown 777 /var/opengrok/etc
$ sudo mkdir -p /var/opengrok/src 
$ sudo chown 777 /var/opengrok/src

7. 원하는 코드를 /var/opengrok/src 에 복사를 하거나 다운받습니다.
(opengrok 으로 소스 찾기를 수행할 소스 전체말입니다)

8. bin 폴더로 이동한 후,  index 를 수행합니다. 
(소스 양에 따라 시간이 오래 걸릴 수 있습니다. 이 과정이 제일 중요합니다. 인덱싱을 하지 않으면 검색을 할 수 없으니깐요... ^^; )

$ cd /usr/opengrok/bin
$ sudo ./OpenGrok index

자 이렇게 한 후, http://<YOUR_WEBAPP_SERVER>:<WEBAPPSRV_PORT>/source 로 가시면
opengrok 을 이용하여 소스를 빠르게 검색할 수 있습니다. 


참고로 opengrok 을 사용하기 위해,
tomcat6, tomcat6-admin,  Exuberant Ctags 를 설치하였습니다.
2012. 1. 28. 23:27

설치된 패키지 정보 추출

가끔 설치된 패키지에 대한 정보를 얻고 싶을 때가 있습니다. 예를 들면 tomcat6 를 설치했는데 이 녀석들이 당췌 어디에 깔렸는지를 알수가 없을 때입니다. 여러 매뉴얼을 보면 tomcat의 특정 파일을 수정하라고 하는데 이 녀석이 어디에 깔리는 지를 모르니 이것 참 답답하더군요. 그래서 혹시나 해서 설치된 패키지에 대한 정보를 추출하는 방법이 없을까 라는 호기심을 가지고 구글링을 해보았습니다. 

역시나 구글신님은 아주 유용한 정보를 제공해 주었습니다.

dpkg -L tomcat6 라는 명령이 바로 그것입니다. 결과는 아래와 같습니다.

sskk@ubuntu:/usr/opengrok/bin$ dpkg -L tomcat6
/.
/var
/var/log
/var/log/tomcat6
/var/lib
/var/lib/tomcat6
/var/lib/tomcat6/webapps
/var/lib/tomcat6/common
/var/lib/tomcat6/common/classes
/var/lib/tomcat6/server
/var/lib/tomcat6/server/classes
/var/lib/tomcat6/shared
/var/lib/tomcat6/shared/classes
/var/cache
/var/cache/tomcat6
/etc
/etc/tomcat6
/etc/tomcat6/Catalina
/etc/tomcat6/Catalina/localhost
/etc/tomcat6/catalina.properties
/etc/tomcat6/logging.properties
/etc/tomcat6/context.xml
/etc/tomcat6/server.xml
/etc/tomcat6/tomcat-users.xml
/etc/tomcat6/web.xml
/etc/tomcat6/policy.d
/etc/tomcat6/policy.d/01system.policy
/etc/tomcat6/policy.d/02debian.policy
/etc/tomcat6/policy.d/03catalina.policy
/etc/tomcat6/policy.d/04webapps.policy
/etc/tomcat6/policy.d/50local.policy
/etc/init.d
/etc/init.d/tomcat6
/etc/cron.daily
/etc/cron.daily/tomcat6
/usr
/usr/share
/usr/share/doc
/usr/share/doc/tomcat6
/usr/share/doc/tomcat6/copyright
/usr/share/doc/tomcat6/changelog.Debian.gz
/usr/share/tomcat6-root
/usr/share/tomcat6-root/default_root
/usr/share/tomcat6-root/default_root/index.html
/usr/share/tomcat6-root/default_root/META-INF
/usr/share/tomcat6-root/default_root/META-INF/context.xml
/usr/share/tomcat6
/usr/share/tomcat6/defaults.template
/usr/share/tomcat6/defaults.md5sum
/var/lib/tomcat6/logs
/var/lib/tomcat6/work
/var/lib/tomcat6/conf
/usr/share/doc/tomcat6/README.Debian.gz


그리고 dpkg -l tomcat6 는 패키지 리스트를 보여줍니다. 결과는 아래와 같습니다.
sskk@ubuntu:/usr/opengrok/bin$ dpkg -l tomcat6
Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name              Version           Description
+++-=================-=================-==================================================
ii  tomcat6           6.0.28-2ubuntu1.5 Servlet and JSP engine

그리고 aptch-cache search 를 이용하는 방법이 있는데 이 명령의 결과는 다음과 같습니다.

sskk@ubuntu:/usr/opengrok/bin$ apt-cache search tomcat6
libtomcat6-java - Servlet and JSP engine -- core libraries
tomcat6 - Servlet and JSP engine
tomcat6-admin - Servlet and JSP engine -- admin web applications
tomcat6-common - Servlet and JSP engine -- common files
tomcat6-docs - Servlet and JSP engine -- documentation
tomcat6-examples - Servlet and JSP engine -- example web applications
tomcat6-user - Servlet and JSP engine -- tools to create user instances


2011. 10. 29. 06:29

Linux or ubuntu Directory structure

Source: http://www.ubuntugeek.com/linux-or-ubuntu-directory-structure.html 

In the Linux operating system, all filesystems are contained within one directory hierarchy. The root directory is the top level directory, and all its subdirectories make up the directory hierarchy. This differs to other operating systems such as MS-Windows which applies a separate hierarchy for each device and partition.

  • /bin - binary applications (most of your executable files)
  • /boot - files required to boot (such as the kernel, etc)
  • /dev - your devices (everything from drives to displays)
  • /etc - just about every configuration file for your system
  • /etc/profile.d - contains scripts that are run by /etc/profile upon login.
  • /etc/rc.d - contains a number of shell scripts that are run on bootup at different run levels. There is also typically an rc.inet1 script to set up networking (in Slackwar), an rc.modules script to load modular device drivers, and an rc.local script that can be edited to run commands desired by the administrator, along the lines of autoexec.bat in DOS.
  • /etc/rc.d/init.d - contains most of the initialization scripts themselves on an rpm-based system.
  • /etc/rc.d/rc*.d - where “*” is a number corresponding to the default run level. Contains files for services to be started and stopped at that run level. On rpm-based systems, these files are symbolic links to the initialization scripts themselves, which are in /etc/rc.d/init.d.
  • /etc/skel - directory containing several example or skeleton initialization shells. Often contains subdirectories and files used to populate a new user’s home directory.
  • /etc/X11 - configuration files for the X Window system
  • /home - locally stored user files and folders
  • /lib - system libraries (similar to Program Files)
  • /lost+found - lost and found for lost files
  • /media - mounted (or loaded) devices such as cdroms, digital cameras, etc.
  • /mnt - mounted file systems
  • /opt - location for “optionally” installed programs
  • /proc - dynamic directory including information about and listing of processes
  • /root - “home” folder for the root user
  • /sbin - system-only binaries (see /bin)
  • /sys - contains information about the system
  • /tmp - temporary files
  • /usr - applications mainly for regular users
  • /var - mainly logs, databases, etc.
  • /usr/local/bin - the place to put your own programs. They will not be overwritten with upgrades.
  • /usr/share/doc - documentation.
2011. 3. 9. 23:13

[Ubuntu] 설치된 패키지 깔끔하게 제거하기

웹서핑을 하다가 다음과 같은 내용의 Q&A 게시판을 보았습니다.

apache2.conf 파일이 존재하지 않는다는 타이틀로, 처음 아파치를 설치했다가 아파치를 삭제를 했답니다. 게다가 /etc/apache2 디렉토리는 수동으로 지워버렸구요.

이렇게 한 후 다시 아파치를 설치해 보니 /etc/apache2/apache2.conf 파일이 존재하지 않는다는 내용입니다.

이 질문에 대한 답변으로는 아파치를 삭제할 때 아래 명령과 같이 하여 apt cache 를 제거해 준 후 다시 설치를 하면 된다는 내용입니다.

$ sudo apt-get remove --purge apache2
$ sudo apt-get clean
$ sudo apt-get install apache2

여기서 주의 깊게 봐야 할 부분은 --purge 옵션입니다. 기본적으로 debian 계열(우분투 포함)은 설정 파일과 같은 특정 파일을 관리하고 있습니다. 이 파일들은 --purge 옵션을 사용할 때에만 제거될 수 있습니다. 

다시 처음부터 설치하고 싶은 경우 삭제할 때 --purge 를 잊지 말아야겠습니다.

2011. 3. 9. 22:59

파일 또는 디렉토리 찾기

현재 디렉토리에서, pl 확장자를 가진 모든 파일 찾기, 하위 디렉토리까지 모두 검색

$ find -name '*.pl'

루트에서부터, pl 확장자를 가진 모든 파일 찾기

$ find / -name '*.pl'

루트에서부터 디렉토리 이름이 et 로 시작하는 모든 디렉토리 찾기

$ find / -name 'et*' -type d

참고: 

2011. 3. 7. 23:19

우분투 서버 ssh 설정

- 설치
$ sudo apt-get install openssh-server

- 서비스를 재시작 한다.
$ sudo /etc/init.d/ssh restart

- 서비스 허용
$ sudo gedit /etc/hosts.allow 
   sshd: 192.168.10.61

- 실행 확인
$ ps ax | grep ssh

$ sudo netstat -ntlp | grep ssh

자세한 내용은 아래 링크 참고
2011. 3. 7. 22:57

명령어 라인에서 파일 다운로드 하는 방법

우분투 서버를 운영하다가 특정 파일을 명령어 라인에서 다운로드 받아야 할 필요가 생겻습니다. 그렇게 찾아보니 wget 이라는 고마운 녀석이 있었네요.

우분투에서는 다음과 같이 설치합니다.

$ sudo apt-get install wget

그리고 원하는 링크의 주소를 입력하여 파일을 다운로드 받습니다.

$ wget http://www.sevenacross.com/photos.zip

정말 쉽죠?

근데 wget 이라는 녀석은 알고보면 더욱 대단한 녀석이군요.
다음 명령을 입력하면 전체 웹사이트를 다운로드 받습니다. wget 이 다운로드할 링크의 depth 를 지정합니다.

$ wget -r -l 1 http://www.yahoo.com/

이 외에도 많은 재미난 것들을 할 수 있는데 좀더 자세한 내용을 아래 링크를 참고하세요~


2011. 2. 23. 00:42

접속해 있는 사용자에게 메시지 보내기

$ write [user account]

입력 후 메시지를 전송하면 해당 사용자에게 내용이 전송됩니다.

현재 서버에 접속한 전체 사용자에게 메시지를 보내고 싶은 경우에는 wall 명령을 사용합니다.

$ wall

을 입력하고 엔터를 칩니다. 그러고 나서 보낼 메시지를 입력하고 Ctrl + D 키를 누르면 해당 메시지가 전송됩니다.

그외 mesg 를 이용하여 write 수신 여부를 설정할 수 도 있는 것 같습니다. 자세한 내용은 아래 링크 참고하세요.

2011. 2. 20. 16:23

우분투에서 svn 구축

업데이트: svn 을 운영하는 폴더가 /home/usr/svn-repos 에서 /var/svn-repo 로 변경하였습니다. 1. subversion 을 먼저 설치합니다.

$ sudo apt-get install subversion

2. svn 을 위한 폴더를 생성합니다.

$ su mkdir /var/svn-repo

3. svn 저장소 생성 (svn-repo 위치는 환경에 맞게 변경하세요)

$ svnadmin create /var/svn-repo

4. 외부에서 접속할 수 있도록 svn 서버 구축
(아래 명령을  /etc/rc.local  에 추가하면 시스템이 시작될 때마다 svn 이 가동되도록 할 수 있습니다.) 

$ svnserve -d -r /var/svn-repo

-d: daemon mode
 -r: root of directory to server

5. 사용자 권한 설정

$ vi /var/svn-repo/conf/svnserve.conf

아래 내용을 적절하게 변경

[general]
anon-access = none
auth-access = write
password-db = passwd

$ vi /var/svn-repo/conf/passwd

[users]
#harry = harryssecret
#sally = sallysecret
user = 1234qwer

보다 자세한 내용은 아래 원본을 참고하세요.