Monday, August 11, 2014

How to know what program is listening on a given port?


I face this issue alot where I need to know list of occupied ports and the pids, I keep forgetting the commands so I thought about posting them here for future references and for anyone who needs it :
 
I use this command to have a full detail :
sudo netstat -taupen

if I need to know exactly which one is listening on specific port (i.e. 8080) I use this :
 
sudo netstat -tapen | grep ":8080"


P.S: the above commands for ubuntu OS, I have not tried them on over distributions
 

Sunday, January 26, 2014

Recover unreachable EC2 CentOS instance

So .. I was working for three days setting up a CentOS ec2 instance environment, and I was using root credentials to login into the VM. 

I decided to stop using password and start using SSH Keys since I am going to share the VM with other developers. So I setup the ssh authorized keys properly and dropped the root password but I forgot to tweak ssh configuration to permite Empty Passwords! and I got stuck outside the VM with password prompt that does not accept any single damn word! :)

So, the simplest solution I found on the internet was to mount the volume to another ec2 instance, fix the password settings and put it back to the unreachable ec2 instance.

Here are the steps :

  • First you need to setup Amazon ec2 API tool
  • Get instance id from ec2
  • Get volume id from ec2
  • Stop the unreachable instance
  • Detach the volume from unreachable instance
  • Start the debugger instance
  • attach the volume to the debugger instance
  • ssh the debugger instance
  • mount the volume
  • fix the ssh setting to enable/permits empty passwords
  • unmount the volume
  • detatch the volume from the debugger instance
  • attach the volume to the unreachable instance
  • now try to ssh, if it did not work you need to repeat the steps and keep fixing the configs until it works.
 I will try to edit this post to provide more details soon. But for now, hope this helps you to fix your problem, you can leave a comment if you need any help!