Programmer's Blog

Programmer's reference

Monthly Archives: August 2014

[Linux] git operations

//1.To open an local repository, go into the directory and then
$> git init --bare

//note that for clone and commit to the repo, the repo must be a bare one,

2. clone files from remote location like SSH
$> git clone ssh://<IP>/mnt/git

3. force add files where their filenames are in gitignore
$> git add -f <file name>
$> git commit -a -m "description"
$> git push origin master

4. To add empty folders, you must include an empty file in each 
of them, otherwise git will not add the files

5.Branching
$>  git checkout -b branchname

6. merging files with master
$> git checkout master
$> git merge a.txt

[Linux] checking library linkage of bin

$> ldd program

//to show library of ordinary bin
$> ldd `which program`

[Denyhosts] remove an IP address that DenyHosts blocked

If you have been accidentally locked out of one of your hosts (because DenyHosts has added it to /etc/hosts.deny you may have noticed that simply removing it from /etc/hosts.deny does not in itself correct the issue) since DenyHosts keeps track of the attempts in the WORK_DIR files. In order to cleanse the address you will need to do the following:

author adds: WORK_DIR is usually /usr/share

  1. Stop DenyHosts
  2. Remove the IP address from /etc/hosts.deny
  3. Edit WORK_DIR/hosts and remove the lines containing the IP address. Save the file.
  4. Edit WORK_DIR/hosts-restricted and remove the lines containing the IP address. Save the file.
  5. Edit WORK_DIR/hosts-root and remove the lines containing the IP address. Save the file.
  6. Edit WORK_DIR/hosts-valid and remove the lines containing the IP address. Save the file.
  7. Edit WORK_DIR/user-hosts and remove the lines containing the IP address. Save the file.
  8. (optional) Consider adding the IP address to WORK_DIR/allowed-hosts
  9. Start DenyHosts

Note: Not all of the WORK_DIR files will contain the IP address so you may want to use grep to determine which files contain the IP address.

source: denyhosts.sourceforge.net

[SSH] restriction the permission of root

//Sometimes there are brute forcers of ssh, 
//to restrict the access of the root

$> vim /etc/ssh/sshd_config

//Then modify the following lines
PermitRootLogin no
DenyUsers root
#StrictModes yes
MaxAuthTries 5

[Linux] configuration of services

//service command - list running services

$> service --status-all
$> service --status-all | grep ntpd
$> service --status-all | less

//Print the status of any service

//To print the status of apache (httpd) service:
$> service httpd status

//List all known services (configured via SysV)
$> chkconfig --list

//List service and their open ports
$> netstat -tulpn

//Turn on / off service
$> ntsysv
$> chkconfig service off
$> chkconfig service on
$> chkconfig httpd off
$> chkconfig ntpd o