2015年7月1日 星期三

[How To] identify a ssh bash session in linux

Very simple just edit .bash_profile

= = =
#
# ~/.bash_profile
#

[[ -f ~/.bashrc ]] && . ~/.bashrc
skip_x="0"

if [ -n "$SSH_CLIENT" ] || [ -n "$SSH_TTY" ]; then
    echo "THIS IS AN SSH SESSION"
    skip_x="1"
fi


#check if x started


ps aux | grep tty |grep startx 2>&1 > /dev/null
if [ "$?" == "0" ]; then
    skip_x="1"
fi

if [ "$skip_x" == "0" ]; then
    exec startx
fi

= = =

2015年6月7日 星期日

[How To] Lenovo Thinkpad run in full speed with battery removed in linux

After using for nearly 9 years (since 2006) of my thinkpad X60 battery. It cannot be charged in a Saturday. As lenovo will limit the CPU speed when the notebook removed the battery. It decrease the performance a lot when battery removed. So for this case, I have searched for a solution.

Let's see my setup:
Lenovo Thinkpad X61 T8300 2.4GHz

How to override it:

When the battery was removed, Lenovo limit the CPU speed in bios, for this case, setting the  scaling_max_freq will not work.

#To see which frequency of the CPU you can set, you may:
$ cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_available_frequencies
2401000 2400000 2000000 1600000 1200000 800000


#So To override the BIOS limit:
echo 1 > /sys/module/processor/parameters/ignore_ppc

#replace the 2400000 for your max CPU speed
for x in /sys/devices/system/cpu/cpu[0-1]/cpufreq/;do
  echo 2400000 > $x/scaling_max_freq
done



Very nice and done.

Just a reminder that when override the bios limit may harm the mainboard. For this case, it is highly recommand to use i7z or phc-intel to lower the voltage of the processors (I have set it before that). It may have less chance for overloading the mainboard.

Cheers.

= = =
reference:
http://blog.patshead.com/2013/04/my-bios-is-limiting-my-cpu-clock-speed.html

2015年6月6日 星期六

[How To] Lower the heat of your computer without any hardware changes in Windows

[How To] Lower the heat of your computer without any hardware changes

Recently I have used the computer of my wife. It is not a fast computer but the computer case blow out hot wind and make the bedroom very hot after starting the computer. Even if I start the speedstep on CPU (or CnQ for AMD processors). The hot wind still blow out from the computer.

And I have found a solution by using a software called "Throttle Stop" you may find it in the following link:

http://www.techpowerup.com/downloads/2288/throttlestop-6-00/

And for the right setting, you also need the following software too:
hwmonitor: http://www.cpuid.com/softwares/hwmonitor.html
 Helps to monitor the voltage as well as the CPU temperature

and

intelburntest easy to find in google
Helps to fullload your CPU to test the stability of your computer

What you need to do is to undervolt of the CPU power and test for the stability. It will not harm on any of the performance.

1. Start intelburntest, hwmonitor and Throttle Stop
2. Start intelburntest
3. in Throttle Stop, lower the VID by pressing the down arrow.
4. If your computer freeze up, start from 1 but increase a little of the last value
5. If intelburntest can pass for some testes, your computer should be more or less stable.
6. Run " Throttle Stop" at start up.


The main advantage for undervolt not only the heat. But also the power consumption of your computer and also the life of electric component on the mainboard. Also, undervolt can help CPU to emmit less heat and can help to slower the CPU fan for less noice. Few steps for more advantages. Why not do it.

My Intel Core 2 6420 undervolt during fullload from 1.35v to 1.1875v

 Cheers for less heat and save the earth

2015年5月23日 星期六

[How To] turn arch linux box to a wireless Access Point in the simplest way

Access point setting may be a little difficult for general linux user, I would like to introduce a one step way to use your linux box with a USB wifi dongle to change it to a wireless AP

1. Identify your USB wifi dongle support AP mode or not.
In order to turn your USB wifi to Access Point, your USB dongle must support AP Mode. you may check if it is supported by following:

$iw list
Wiphy phy1
    max # scan SSIDs: 4
    max scan IEs length: 2285 bytes
    Retry short limit: 7
    Retry long limit: 4
    Coverage class: 0 (up to 0m)
    Device supports RSN-IBSS.
    Supported Ciphers:
        * WEP40 (00-0f-ac:1)
        * WEP104 (00-0f-ac:5)
        * TKIP (00-0f-ac:2)
        * CCMP (00-0f-ac:4)
        * 00-0f-ac:10
        * GCMP (00-0f-ac:8)
        * 00-0f-ac:9
        * CMAC (00-0f-ac:6)
        * 00-0f-ac:13
        * 00-0f-ac:11
        * 00-0f-ac:12
    Available Antennas: TX 0 RX 0
    Supported interface modes:
         * IBSS
         * managed
         * AP
         * AP/VLAN
         * monitor
         * mesh point
                  ...

 If you plug in your usb dongle and the Supported Interface modes do not have the "AP" mode, you need another usb module. Most likely for my personsal recommendation Atheros Chipset is a good choice.

2. Introduce to you a create_ap script. You may find it in the following link:
https://bbs.archlinux.org/viewtopic.php?pid=1269258

or from AUR
https://aur.archlinux.org/packages/create_ap/

Just install it and with the dependencies.

Just simply run a command

#create_ap wlan0 eth0 MyAccessPoint MyPassPhrase

And it is Done!! How come it is so easy.

There is a word for Chinese People "前人種樹後人蔭" "People plant trees, childen cools under tree"

Thanks for open source

2015年5月19日 星期二

[How to] Block ssh brute-force attack using sshguard in linux


In case your Linux box have provided a ssh function and connect to a public internet IP directly, in most case you will face a lot of brute-force attack. For this case, sshguard can help to lower the rate of the attack.

How it works
For simply, sshguard read logs from sshd and block suspicious attack by iptables.

In order to view if you are being attacked:
$journalctl -axe
...
 5▒▒▒ 19 12:28:10 localhost sshd[22109]: Connection closed by 70.60.248.30 [preauth] <==== Port Scan
 5▒▒▒ 19 12:28:34 localhost sshd[22111]: Did not receive identification string from 195.154.55.58
 5▒▒▒ 19 12:28:35 localhost sshd[22112]: Invalid user ubnt from 195.154.55.58
 5▒▒▒ 19 12:28:35 localhost sshd[22112]: input_userauth_request: invalid user ubnt [preauth]
 5▒▒▒ 19 12:28:36 localhost sshd[22112]: pam_tally(sshd:auth): pam_get_uid; no such user
 5▒▒▒ 19 12:28:36 localhost sshd[22112]: pam_unix(sshd:auth): check pass; user unknown
 5▒▒▒ 19 12:28:36 localhost sshd[22112]: pam_unix(sshd:auth): authentication failure; logname= uid=0 euid=0 tty=ssh ruser= rhos
 5▒▒▒ 19 12:28:38 localhost sshd[22112]: Failed password for invalid user ubnt from 195.154.55.58 port 54126 ssh2
 5▒▒▒ 19 12:28:38 localhost sshd[22112]: error: Received disconnect from 195.154.55.58: 3: com.jcraft.jsch.JSchException: Auth
 5▒▒▒ 19 12:28:38 localhost sshd[22112]: Disconnected from 195.154.55.58 [preauth]
 5▒▒▒ 19 12:28:39 localhost sshd[22115]: Invalid user admin from 195.154.55.58
 5▒▒▒ 19 12:28:39 localhost sshd[22115]: input_userauth_request: invalid user admin [preauth]
 5▒▒▒ 19 12:28:40 localhost sshd[22115]: pam_tally(sshd:auth): pam_get_uid; no such user <=== Attack
 5▒▒▒ 19 12:28:40 localhost sshd[22115]: pam_unix(sshd:auth): check pass; user unknown
 5▒▒▒ 19 12:28:40 localhost sshd[22115]: pam_unix(sshd:auth): authentication failure; logname= uid=0 euid=0 tty=ssh ruser= rhos
 5▒▒▒ 19 12:28:42 localhost sshd[22115]: Failed password for invalid user admin from 195.154.55.58 port 51840 ssh2
 5▒▒▒ 19 12:28:43 localhost sshd[22115]: error: Received disconnect from 195.154.55.58: 3: com.jcraft.jsch.JSchException: Auth
 5▒▒▒ 19 12:28:43 localhost sshd[22115]: Disconnected from 195.154.55.58 [preauth]
 5▒▒▒ 19 12:28:44 localhost sshd[22117]: pam_tally(sshd:auth): Tally overflowed for user root <=== Attack
 5▒▒▒ 19 12:28:44 localhost sshd[22117]: pam_unix(sshd:auth): authentication failure; logname= uid=0 euid=0 tty=ssh ruser= rhos
 5▒▒▒ 19 12:28:46 localhost sshd[22117]: Failed password for root from 195.154.55.58 port 54190 ssh2 <=== Attack

... 

Installation

Very simple
# pacman -S sshguard
# iptables -N sshguard
# iptables -A INPUT -p tcp --dport 22 -j sshguard
# iptables-save > /etc/iptables/iptables.rules

# systemctl start sshguard.service
# systemctl enable sshguard.service


And you may find from the log
$journalctl -axe 
 5▒▒▒ 19 12:28:46 localhost sshguard[26588]: Blocking 195.154.55.58:4 for >630secs: 40 danger in 4 attacks over 12 seconds (all 

Nice and done 

2015年5月4日 星期一

Android X86 native experience - Android-x86 4.4r2

Android X86 is a project that can run android natively on X86 computer. I have downloaded and tested the latest release of "Android-x86 4.4r2" which was released on 1Jan 2015, as live CD. The experience is as follows:

1. Hardware
- Lenovo Thinkpad X61 (intel T8300, i965 4GB DDR2, ABGN4965)
- Desktop Computer (intel core 2 duo 6420, G33, 4GB DDR2, AMD HD4670)

2. Testing
It is strange that the laptop gives a very poor experience that the OS crash on the first screen of checking wifi status during inputing the Google Account. I have tested for a couple of times and it still not work. Seems cannot found a solution on web yet. I have tried to use a USB wifi and the issue is still the same.

For the Desktop computer, it is strange that everything works out of box.
Performance is great, very fast and no a little lag.
CPU works great with Speedstep
Graphics card works well with acclaration
Most app works

Just wanna know if it support MCE remote, or I will buy one or the android x86 media center.

= = =
Download Link:
http://www.android-x86.org/

2015年5月2日 星期六

[How to] Fix the kernel module issues for VirtualBox

As some of the linux users may face issues related to kernel modules, just would like to document how I fix the issue

I was face the issue on the log

VBoxManage: error: Failed to create the host-only adapter
VBoxManage: error: VBoxNetAdpCtl: Error while adding new interface: failed to open /dev/vboxnetctl: No such file or directory
VBoxManage: error: Details: code NS_ERROR_FAILURE (0x80004005), component HostNetworkInterface, interface IHostNetworkInterface
VBoxManage: error: Context: "int handleCreate(HandlerArg*, int, int*)" at line 66 of file VBoxManageHostonly.cpp


To fix it, just load all kernel modules at boot up

# cat /etc/modules-load.d/virtualbox.conf
vboxnetadp
vboxnetflt
vboxpci
vboxdrv





= = =
Nice and Done