Showing posts with label Linux. Show all posts
Showing posts with label Linux. Show all posts

Saturday, January 3, 2015

Bash command to print list of sequential host name

Bash command to print list of sequential host name:

for i in `seq 11 15`; do echo "server${i}"; done



this will print the following hostname:

server11
server12
server13
server14
server15

Saturday, January 11, 2014

Change timezone in debian

To change timezone in debian, you can use the following 2 steps.

1. Edit /etc/timezone with your desired timezone such as America/New_York

2. run the following command as root or use sudo
  
    dpkg-reconfigure tzdata

    If you want to run it non-interactively so you can script it, use the following command:

    dpkg-reconfigure -f noninteractive tzdata





Tuesday, December 17, 2013

Put Linux process on the background and exit

you started a process on the foreground and need to put it in a background so you can exit the ssh shell, then you can run the following:


press [CTRL]+[Z]
bg
disown -h
exit




If you need to start a new process and put in background, you can use the nohup command as follow:

nohup ./loop.sh &



Check ethernet connection speed in Linux

Type the following command to get speed for eth0:

ethtool eth0 | less

OR

ethtool eth0 | grep -i speed


Monday, December 16, 2013

Apache not processing php in suse

If you have php installed on your suse os, but apache is not processing php page, then the following might help solve your problem:

1. edit /etc/sysconfig/apache2, on "APACHE_MODULES=" add "mod_php5"

2. Edit /etc/apache2/sysconfig.d/loadmodule.conf

Add this line for 32 bit OS
LoadModule php5_module /usr/lib/apache2/mod_php5.so

Add this line for 64 bit OS
LoadModule php5_module /usr/lib64/apache2/mod_php5.so


3. run these command
 /etc/init.d/apache2 stop
 /etc/init.d/apache2 start



Monday, December 9, 2013

Test active mode ftp in linux

Ftp is old and insecure, but some people still use it. So here's a way to test it on linux to see if your ftp server is responding to active mode ftp correctly:

for ftp:


ftp ftp-server.com
type your username
type your password
passive off          # this turn off the passive mode, then you can run ls, get, put command
ls
quit


for ftps using lftp (you can type debug to get into debug mode)


implicit (assuming port 990)


lftp ftps://ftp-server.com:990
set ftp:passive-mode off
user username
type your password 
#type ls, get, put command
ls
exit



explict (assuming port 21)


lftp ftp://ftp-server.com
set ftp:ssl-allow-anonymous yes
set ssl:verify-certificate off
set ftp:passive-mode off
set ftp:ssl-force on
set ftp:ssl-allow on
user username
type your password 
#type ls, get, put command
ls
exit







Thursday, April 25, 2013

List only directories or files in a Linux/Unix directory

To list just directories, use this command:

ls -l | egrep '^d'

If you just want the directories name without detail, then use this command:

ls -l | egrep '^d' | awk '{print $NF}'



To list just files, use this command:

ls -l | egrep -v '^d'

If you just want the file names without detail, then use this command:

ls -l | egrep -v '^d' | awk '{print $NF}'


Wednesday, April 10, 2013

"su: No directory!" and "su: No shell" error

Problem:

You can log in as root, but when you try to switch to other user by running "su - username", you get "su: No directory!" error.

example:

command ran:

su - testuser

error:

su: No directory!

You also get "su: No shell" error when you try to run a command as a user by running " su username -c 'echo test' "

example:

su testuser -c 'echo test'

error:

su: No shell

Solution:

The permission on / is set up incorrectly. you probably have drwx for /. Other user need to have execute permission on / in order to solve this problem.

you can fix this by running this command:

chmod o+x /



Old permission:

 # ls -la /

drwx------  19 root     root          22 Sep 28  2009 .
drwx------  19 root     root          22 Sep 28  2009 ..

New permission:

# ls -la /

drwx-----x  19 root     root          22 Sep 28  2009 .
drwx-----x  19 root     root          22 Sep 28  2009 ..



Redirect nohup output to another file

 
Normally, nohup save the output to nohup.out file. But you can change that using the following command:
 
nohup some_command > nohup_new_output.out 2>&1&
 
 
 

Wednesday, April 3, 2013

Converting SSH key format

To convert ssh key in PEM format to OpenSSH format, use this command:

ssh-keygen -i -f pem_format.pub > id_rsa.pub 

To convert ssh key in OpenSSH format to PEM format, use this command:

ssh-keygen -e -f id_rsa.pub > pem_format.pub 

To see the fingerprint of the ssh key use this command:

To see the fingerprint of the ssh key, use this command:

ssh-keygen -l -f id_rsa.pub 

This will return three things:
  • the bit strength
  • the fingerprint
  • the filename


PEM format:

---- BEGIN SSH2 PUBLIC KEY ----
Comment: "4096-bit RSA, converted from OpenSSH by user@machine_name"
AAAAB3NzaC1yc2EAAAABIwAAAgEAwrr66r8n6B8Y0zMF3dOpXEapIQD9DiYQ6D6/zwor9o
39jSkHNiMMER/GETBbzP83LOcekm02aRjo55ArO7gPPVvCXbrirJu9pkm4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