Showing posts with label linux. Show all posts
Showing posts with label linux. Show all posts

OpenVPN: certificate is not yet valid edit

When OpenVPN authentication process fails during a connection attempt with an error message like 'certificate is not yet vaild', check the date of your machine. According to a web source, it is required to have synchronized time between VPN server and client.

Correct time OpenVPN requires client and server to have more or less synchronized time. Therefore make sure that router has correct time. To check it use command date and if you get info about year 1970, you should enable NTP client. Also, ntp server has to be outside of your VPN as time should be corrected before VPN is established. If you have syslog enabled (to local server, or the server outside your VPN), errors like TLS Error: Unroutable control packet received from server_ip:1194 may indicate this problem. (This error message may appear if your certificates are not valid or have expired, too.) If you get an error message saying that your certificate is not yet valid, set the dd-wrt clock to UTC time (in the first configuration page).

To synchronize time, you can use ntpdate tool:

# ntpdate pool.ntp.org

References

  • http://www.dd-wrt.com/wiki/index.php/OpenVPN
  • http://www.justin.my/2011/04/how-to-synchronize-date-and-time-in-linux-console/

Linux Mint: Can't change my laptop's screen brightness! edit

Edit /etc/default/grub and add acpi_osi, acpi_backlight options.

GRUB_CMDLINE_LINUX_DEFAULT="i915.modeset=1 acpi_osi= acpi_backlight=vendor"

Also checkout the kernel parameters under /sys/class/backlight/

References

http://forums.linuxmint.com/viewtopic.php?f=109&t=113900

가상머신과 sshfs를 이용한 Samba 터널링 edit

http://jinnycreepin.tistory.com/17 으로 이동

리눅스 민트(우분투) 데스크톱 환경에서 한/영키를 누를때 Alt키가 같이 눌린다? edit

Linux Mint(Ubuntu): Hangul key is also Alt key?

아래 명령을 루트 유저로 실행:
Try this command as root user:

# xmodmap -e 'remove mod1 = Hangul'

자동 시작 스크립트 만들기; Make startup script

/etc/init.d/fix_hangul_key.sh:

#!/bin/bash
xmodmap -e 'remove mod1 = Hangul'
# chmod 755 /etc/init.d/fix_hangul_key.sh
# update-rc.d -f fix_hangul_key.sh defaults

노트: update-rc.d 시스템 명령은 최신버전의 우분투 환경에서 동작하지 않을 수 있습니다.
Note: update-rc.d may not working with latest version of Ubuntu.

Linux Mint: System is very slow! edit

It's caused by drm_kms_helper and I don't know what it is.

First, upgrade your system(apt-get update && apt-get upgrade && apt-get dist-upgrade) including kernel.

To disable it:

# echo N > /sys/module/drm_kms_helper/parameters/poll
# echo "options drm_kms_helper poll=N">/etc/modprobe.d/local.conf

To disable at start up, add below script to /etc/init.d/ and add using update-rc.d.

/etc/init.d/disable-krm_kms_helper.sh:

#/bin/bash
echo N> /sys/module/drm_kms_helper/parameters/poll
# update-rc.d -f disable-krm_kms_helper.sh defaults

After awhile, somehow the lags are gone away.

References

https://bugs.launchpad.net/linuxmint/+bug/1122219

Linux Mint: Things to customize after initial install edit

  • Edit /etc/apt/sources.list to your local mirror - Add your country code(e.g KR for South Korea) to URLs
  • Upgrade system using apt-get update && apt-get upgrade && apt-get dist-upgrade
  • Install language support from system menu 'lanauge support' and install ibus to toggle between languages. - ibus and ibus-korean for korean users
  • If system is very slow, disable drm_kms_helper - see this post

References

http://fineday2love.tistory.com/86

iptables: Set rules to make firewall acts like a home routers. edit

Home routers accept connections established from inside and deny incoming connections that isn't

Initialize iptables rules:

# iptables -F
# iptables -X
# iptables -Z

Set default chain policies:

# iptables -P INPUT DROP
# iptables -P FORWARD DROP
# iptables -P OUTPUT ACCEPT

Accept on localhost:

# iptables -A INPUT -i lo -j ACCEPT
# iptables -A OUTPUT -o lo -j ACCEPT

Allow established sessions to receive traffic:

# iptables -A INPUT -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT

Save rules:

# iptables-save

References

http://superuser.com/questions/427458/deny-all-incoming-connections-with-iptables http://blog.daum.net/hypermax/6

How to mount linux ramdisk edit

You should use tmpfs for that instead.
mount -t tmpfs -o size=10g none /mnt/point

HDD S.M.A.R.T Value Test from Linux Console / Find out each HDD's serial number edit

The package name for smartctl is smartmontools

# apt-get install smartmontools

It's really simple

# smartctl -H /dev/sda

To find out each hdd's serial number, use hdparm

# hdparm -I /dev/sda

sshfs - Can't kill a disconnected process edit

I'm using sshfs through forward ssh tunnel connection and got disconnected unexpectly.

Note: Using sshfs through ssh tunneling connection is such a way to wasting computer power because it encrypts data double times. First, the tunnel connection, Second, sshfs connection itself. However if you're using encfs, there's not much of an options are available. I think this is the easy and best way to mount a encrypted directory point made by encfs(other users can't even access the encrypted directory. not even root.) other options like NFS requires root access with some tricks.

The problem was:

  • I couldn't see my home directory(ls -al command hangs) - where the sshfs mounting point directory was located.
  • command df -sh hangs too.

My home directory is /home/myhome/(for example.) and the mounting point was /home/myhome/sshfsdir. It seemed like every I/O processes that access my home directory(which is /home/myhome/) hangs due to unable to read the one of child nodes. mounting point directory /home/myhome/sshfsdir/ was one of them.

However I was able to access the / directory as root user(probably any user too), I was able to un-mount sshfs mounting point using fusermount command with the lazy option -z.

# fusermount -uz /home/myhome/sshfsdir/

Then I checked sshfs process(ps -ef | grep sshfs). there was still one sshfs process hangs under the background. I couldn't kill it by kill PID command. so I googled.

If a sshfs process keep hangs under the background on your system or any other processes that you can't kill, try to use the option -KILL for kill command.

# kill -KILL PID
I've seen this when I drop a connection to an active screen then reconnect. The linked bug describes the problem as I see it. What appears to happen is that screen is trying to notify the tty that holds it that it is about to leave, but since the tty is hung due to a dropped connection it has to wait for the timeout to happen (which is upwards of five minutes in some cases). To fix it, I do this: figure out which tty is holding on to the screen session ps -ef | grep screen | grep pty find the login bash that is associated with that tty ps -ef | grep bash | grep $PTY kill that bash kill -KILL $PID This causes screen to complete its disconnect correctly, and lets you reconnect normally. See here for an example script automating this somewhat.

I found a wiki article that explains this problem softly:

killing me softly

or, how to be as gentle as possible when killing a Linux/Unix process

I recommend kills in this order, with a short delay between each:

  1. kill -TERM (same as kill without an argument)
  2. kill -HUP (same as closing the window)
  3. kill -INT (same as Ctrl-C)
  4. kill -QUIT (same as Ctrl-\)
  5. kill -PIPE (same as quitting the program you've piped it into, e.g. less)
  6. kill -KILL (a.k.a. -9)

The only thing that can ignore a KILL signal is I/O. If your process still won't die when you use KILL, there is often no option but to reboot the system. This is one of my pet peeves about Linux.

Template

Here's a bash function to do the job:

kill_softly()
{
    for sig in TERM HUP INT QUIT PIPE KILL; do
        echo "kill -$sig $@"
        if ! kill -$sig "$@"; then
            # the kill command failed - this usually means that the process is now dead
            break
        fi
        sleep 2
    done
}

Generate SSH Key (for AndFTP) edit

http://jinnycreepin.tistory.com/21 으로 이동

Add sudoers edit

Instead of editing /etc/sudoers, you can add a user to sudoers by adding the user to the group 'sudo'.

For example:

# usermod -a -G sudo user

Linux add/remove an existing user to a gorup edit

Add an existing user to a group

# usermod -a -G GROUP USER

Remove an existing user form a group

# gpasswd -d USER GROUP
http://www.howtogeek.com/50787/add-a-user-to-a-group-or-second-group-on-linux/ http://unix.stackexchange.com/questions/29570/how-do-i-remove-a-user-from-a-group

encfs - fuse: failed to open /dev/fuse: Permission denied edit

encfs - fuse: failed to open /dev/fuse: Permission denied
That group may not be present for the current shell session. Just do the following.
grep  /etc/groups
to see the list of groups in which the user has been added. To take effect, you may have to logout and login again. Or it would take effect after the next reboot.
chmod 660 /dev/fuse

Get root permission and save a file inside of vim editor edit

http://stackoverflow.com/questions/1005/getting-root-permissions-on-a-file-inside-of-vi
:w !sudo tee %

리눅스 환경에서 7za 압축할때 특정파일 제외시키기 edit

http://sourceforge.net/projects/p7zip/forums/forum/383043/topic/1909015

리눅스 환경에선 작은따옴표('')로 -xr옵션을 감싸주어야 에러가 안난다.

7za a -mx9 -ms '-xr!*.m2ts' test.7z

-x-xr의 차이

Notice -xr instead of -x. The r indicates recursive so it can match excluded files in deep folder hierarchies.

-xr옵션은 하위의 모든 폴더들에서도 적용된다.

커널 패닉 이후 자동으로 리붓시키기. edit

만약 원격지에 있는 서버가 갑자기 응답하지 않는다면 어떻게 해야 할까. 원격으로 컴퓨터를 조종할 수 있는 IP KVM이나 네트워크 콘솔따위가 없다면, 원격지에 있는 멍청한 서버는 기본값으로 사람이 물리적으로 리셋해줄때까지 기다린다.

설정값이 아래와 같이 설정되어 있다면 해당 시스템은 패닉 후 사람의 손길만을 기다린채 전기만 계속 우걱우걱 하신다.

[root@linux23 ~]# cat /proc/sys/kernel/panic
0
[root@linux23 ~]# sysctl -a | grep kernel.panic
kernel.panic = 0
[root@linux23 ~]# 

최근에 내 서버에도 일어난 일이었고, 인터넷으로 온갖 방법을 찾아봤지만 예방법밖에 없다. 결국 커널 패닉 이후 동작을 미리 설정하지 않은 상태에서 일어난 커널 패닉은 원격지에서 물리적인 방법으로 리셋시켜주는 방법밖에 없다.

두가지 커널 옵션이 있다.

  • kernel.panic = n : 커널 패닉이 발생했을때 n초 후에 시스템을 리부팅 한다.(0==off)
  • kernel.panic_on_oops = 0/1 : 1이면 oops를 커널 패닉으로 간주한다.

바로 적용하려면 아래와 같이 한다.

[root@linux23 ~]# echo "10" > /proc/sys/kernel/panic
0
[root@linux23 ~]# cat /proc/sys/kernel/panic
kernel.panic = 10
[root@linux23 ~]# 

영구적으로 적용하고자 /etc/sysctl.conf를 수정한다.

/etc/sysctl.conf:
kernel.panic = 10
kernel.panic_on_oops = 1

sysrq 명령을 원격으로 할 수 있게 해주는 ipt_sysrq

http://marek.terminus.sk/prog/ipt_sysrq.shtml

Sometimes a remote server hangs and only responds to icmp echo request (ping). Every administrator of such machine is very unhappy because (s)he must go there and press the reset button. It takes a long time and it's inconvenient. So here is a solution. Use the Network Magic SysRq and you will be able to do more than just pressing a reset button. You can remotely sync disks, remount them read-only, then do a reboot. And everything comfortably and only in a few seconds. ;-)

YES!!!

edit

http://todayis.tistory.com/276
우분투나 데비안에서 고정 ip를 설정하는 방법이다.
데비안의 경우 설치 시 ip를 설정할 수 있지만, 우분투의 경우는 DHCP로 잡히기 때문에.. 필요에 따라 다시 설정을 해 주어야 한다.

먼저 네트워크 인터페이스를 내린다(중지 시킨다).
$ sudo ifdown eth0

네트워크 인터페이스 설정 파일을 자신의 상황에 맞게 수정한다.
$sudo vi /etc/network/interfaces
auto lo
iface lo inet loopback

auto eth0
iface eth0 inet static
address 192.168.0.2
netmask 255.255.255.0
network 192.168.0.0
broadcase 192.168.0.255
gateway 192.168.0.1
dns-nameservers 168.126.63.1 168.126.63.2

네임 서버를 수정한다.
$ sudo vi /etc/resolv.conf
nameserver 168.126.63.1
nameserver 168.126.63.2

네트워크 인터페이스를 올린다(다시 동작 시킨다).
$ sudo ifup eth0


ip 를 자동으로 할당받고 싶다면, '/etc/network/interfaces' 에서 iface eth0 inet static 이하의 부분을 iface eth0 inet dhcp 로 수정해 주면 된다.

Linux에서 특정 텍스트내의 문자열 찾기 edit

http://fotobank-textcube.blogspot.com/2010/04/100429-linux에서-특정-텍스트내의-문자열-찾기.html

100429 Linux에서 특정 텍스트내의 문자열 찾기
"가나다" 으로 시작하는건 모두 가져와라~~~(해당 폴더 및 하위폴더)

grep -ir 가나다 * ( 가나다와 * 사이에 한칸 띄워야 함)

"가 나다" 으로 시작하는건 모두 가져와라~~~(해당 폴더 및 하위폴더)

grep -ir 가.나다 * 텍스트사이가 떨어져 있을 경우에는 .으로 표시

리눅스 프로세스 우선순위 변경하기 edit

  • 프로그램을 우선순위를 설정하여 실행할때는 nice를 쓴다.
  • 이미 실행중인 프로세스는 renice로 수정할 수 있다.
  • NICE값이 작은값일수록 우선순위가 높으며 NICE값이 큰값일수록 우선순위가 낮다.
  • NICE값을 0미만으로 수정하려면(우선순위를 높이려면) 루트권한이 필요하다.

이미 실행된 프로세스의 우선순위 수정


우선순위 낮추기


$ renice +10 PID

우선순위 높이기


루트 권한이 필요함.

# renice -1 PID

데비안 기준으로 시스템 백그라운드 서비스들은 NICE값이 -5임.
서버 로드가 높을때 특정 데몬의 우선순위를 높이고싶다면 -1만 해줘도 충분함.


참고 링크


http://www.ibm.com/developerworks/kr/library/l-lpic1-v3-103-6/index.html
<- Older