Hi,
Recently I was trying to write a script for changing password automatically for a user.I required something else for this but I found one similar script while searching over Internet.While I was experimenting with this on my ubuntu 10.10 system, I did a terrible mistake.At the place of username, I put my main account username.Not only this,I used "pwgen" program to generate random password which was there in the script and I blindly used it.
The script I used is below:-
touch pass.txt
chmod 600 pass.txt
# generate a nice secure password and put it in a file
pwgen > pass.txt
# get the password hash
ph=$(makepasswd --clearfrom=pass.txt --crypt-md5 |awk '{print $2}')
# Set the password
usermod -p $ph "username"
Now, first time I used it using sudo, It asked for password.Now this script randomly generated a new passowrd and set for my account.Now, a new password was hashed in /etc/shadow file which I didn't know.Next time, when I used it again,it asked for password which was changed randomly.So,I could not give correct password.
Now, I thought how would I login after next reboot.I asked someone who told me to use a live cd of ubuntu to change shadow file.In shadow file, password is stored encrypted corresponding to each username.Now, I was preparing for a back up.Still, I wasn't sure it will work.
When I rebooted,something clicked in my mind.I booted in recovery mode.Then using root shell, I opened /etc/shadow file.Usually it opens in read-only mode.But since I was root that time, I removed the hash of my username.I removed everything that was there between first 2 colon(:). I did it only for my username and root.Hence, password was omitted.Now I reboot again and reset the password using passwd command and it didn't ask for current password.I didn't know that we could reset our password in recovery mode.
I knew that this similar method worked in ubuntu 8.04. But I thought they removed this as a bug.Now it worked for me.I can't decide if it is a good or bad thing.Since I changed my password in emergency,It is cool. But someone else can access my account by resetting my password.
I am Gaurav kumar, did M.Sc.(tech) in Information Systems from BITS pilani, India (2008-12). Software programmer and founding team member at GreyOrange (2012-present), Volunteer @FeedingIndia
Showing posts with label BITS. Show all posts
Showing posts with label BITS. Show all posts
Monday, March 21, 2011
Monday, November 22, 2010
facemash experience "the social network"
hello people,
I have been constantly watching and listening "The Social Network" since the time I first watched it.Awesome movie.very inspirational.Well,I too thought about writing facemash after watching this.But,I did not want to end up facing punishment like mark.So, I didn't try to insult anyone.Just experiment and wanted to refresh my php and mysql concepts.
What we need is collection of some images.put it in a directory and provide its path in the code.for this example I will use "pics" as directory which has 7 images.Now write one php script to display 2 images randomly and let user click on any of this.Now,one more script to check which image was clicked and calculate the new rank of both image.I am sharing a piece of code here.
require_once("sql.php"); //sql.php connects to the database.
srand(time());
$r1 = rand()%7;
srand(time());
$r2 = rand()%7 ;
while($r1 == $r2)
{
srand(time()) ;
$r2 = rand()%7 ;
}
$query1 = "SELECT * FROM pic WHERE picid = '$r1'";
$result1 = mysql_query($query1);
$row1 = mysql_fetch_array($result1);
$query2 = "SELECT * FROM pic WHERE picid = '$r2'";
$result2 = mysql_query($query2);
$row2 = mysql_fetch_array($result2);
$pic1 = $row1['pic'] ;
$pic2 = $row2['pic'] ;
give image with its link in the html part of the code href='mash.php?id1=$r1&id2=$r2' img src=pics/".$pic1
href='mash.php?id1=$r2&id2=$r1'img src=pics/".$pic2
now when this page redirects to mash.php,new rank of both images is calculated based on the algorithm you wanna use.here, we have defined 3 variables.'h' is no. of hit on the image,'d' no. of times the image has been displayed.'rank' shows point given to image.use get method to catch variables to update database containing no. of hits of an image.
$id1 = $_GET['id1'];
$id2 = $_GET['id2'];
$query1 = "SELECT * FROM pic WHERE picid = '$id1'";
$result1 = mysql_query($query1);
$row1 = mysql_fetch_array($result1);
$query2 = "SELECT * FROM pic WHERE picid = '$id2'";
$result2 = mysql_query($query2);
$row2 = mysql_fetch_array($result2);
$h1 = $row1['h']+1;
$d1 = $row1['d']+1;
$rank1 = [algo to calculate new rank];
$h2 = $row2['h']; // no. of hit remains same for the image not clicked.
$d2 = $row2['d']+1;
$rank2 = [algo to calculate new rank] ;
$res1 = mysql_query("UPDATE pic SET h='$h1',d='$d1',rank='$rank1' WHERE picid='$id1' ") ;
$res2 = mysql_query("UPDATE pic SET h='$h2',d='$d2',rank='$rank2' WHERE picid='$id2' ") ;
So,this was my experience.Worked without any problem.See ya.
I have been constantly watching and listening "The Social Network" since the time I first watched it.Awesome movie.very inspirational.Well,I too thought about writing facemash after watching this.But,I did not want to end up facing punishment like mark.So, I didn't try to insult anyone.Just experiment and wanted to refresh my php and mysql concepts.
What we need is collection of some images.put it in a directory and provide its path in the code.for this example I will use "pics" as directory which has 7 images.Now write one php script to display 2 images randomly and let user click on any of this.Now,one more script to check which image was clicked and calculate the new rank of both image.I am sharing a piece of code here.
require_once("sql.php"); //sql.php connects to the database.
srand(time());
$r1 = rand()%7;
srand(time());
$r2 = rand()%7 ;
while($r1 == $r2)
{
srand(time()) ;
$r2 = rand()%7 ;
}
$query1 = "SELECT * FROM pic WHERE picid = '$r1'";
$result1 = mysql_query($query1);
$row1 = mysql_fetch_array($result1);
$query2 = "SELECT * FROM pic WHERE picid = '$r2'";
$result2 = mysql_query($query2);
$row2 = mysql_fetch_array($result2);
$pic1 = $row1['pic'] ;
$pic2 = $row2['pic'] ;
give image with its link in the html part of the code href='mash.php?id1=$r1&id2=$r2' img src=pics/".$pic1
href='mash.php?id1=$r2&id2=$r1'img src=pics/".$pic2
now when this page redirects to mash.php,new rank of both images is calculated based on the algorithm you wanna use.here, we have defined 3 variables.'h' is no. of hit on the image,'d' no. of times the image has been displayed.'rank' shows point given to image.use get method to catch variables to update database containing no. of hits of an image.
$id1 = $_GET['id1'];
$id2 = $_GET['id2'];
$query1 = "SELECT * FROM pic WHERE picid = '$id1'";
$result1 = mysql_query($query1);
$row1 = mysql_fetch_array($result1);
$query2 = "SELECT * FROM pic WHERE picid = '$id2'";
$result2 = mysql_query($query2);
$row2 = mysql_fetch_array($result2);
$h1 = $row1['h']+1;
$d1 = $row1['d']+1;
$rank1 = [algo to calculate new rank];
$h2 = $row2['h']; // no. of hit remains same for the image not clicked.
$d2 = $row2['d']+1;
$rank2 = [algo to calculate new rank] ;
$res1 = mysql_query("UPDATE pic SET h='$h1',d='$d1',rank='$rank1' WHERE picid='$id1' ") ;
$res2 = mysql_query("UPDATE pic SET h='$h2',d='$d2',rank='$rank2' WHERE picid='$id2' ") ;
So,this was my experience.Worked without any problem.See ya.
Sunday, May 30, 2010
Summer Internship :First week
hi all,
Right now I am at nagda(M.P.) for my internship at GRASIM chemicals.It's been a week and I am enjoying it completely.We are a group of 10 students in chemical division.Normally we go to the plant and visit different manufacturing sites.Due to strict discipline, we wear a helmet which we try to put on and off enormous times.Since I came here,1st thing I was looking for was internet connection but didn't find much options at such a place.After so much analysis, we thought to use GPRS connection.I recharged my airtel sim for unlimited plan.But now I have realized that it is in roaming, so it's slower than i had expected.
Finally we have 2 connections and 6 students in our group.So, we are always experimenting with creating shared connections.Sometimes we use LAN wire to connect.Sometimes,we create wireless ad-hoc and sometimes create proxy server(using privoxy).Till now we are having fun.Yesterday we went to ujjain to visit famous "Mahakaleshwar" temple.There we had a funny incident.When we bought the tickets for returning,the train started taking off.We entered into different class due to rush and ended up paying fine for that.Actually it wasn't fine,it was bribe.We were in no position to negotiate ,so we paid the money.We didn't get the receipt but paid less money and became the integral part of corruption.Although we had done no mistake considering the situation.
anyway that was a lesson for all of us.Now we have 50 days more to live at this place.Hope to spend it nicely.
Right now I am at nagda(M.P.) for my internship at GRASIM chemicals.It's been a week and I am enjoying it completely.We are a group of 10 students in chemical division.Normally we go to the plant and visit different manufacturing sites.Due to strict discipline, we wear a helmet which we try to put on and off enormous times.Since I came here,1st thing I was looking for was internet connection but didn't find much options at such a place.After so much analysis, we thought to use GPRS connection.I recharged my airtel sim for unlimited plan.But now I have realized that it is in roaming, so it's slower than i had expected.
Finally we have 2 connections and 6 students in our group.So, we are always experimenting with creating shared connections.Sometimes we use LAN wire to connect.Sometimes,we create wireless ad-hoc and sometimes create proxy server(using privoxy).Till now we are having fun.Yesterday we went to ujjain to visit famous "Mahakaleshwar" temple.There we had a funny incident.When we bought the tickets for returning,the train started taking off.We entered into different class due to rush and ended up paying fine for that.Actually it wasn't fine,it was bribe.We were in no position to negotiate ,so we paid the money.We didn't get the receipt but paid less money and became the integral part of corruption.Although we had done no mistake considering the situation.
anyway that was a lesson for all of us.Now we have 50 days more to live at this place.Hope to spend it nicely.
Labels:
BITS,
college,
corruption,
internship
Monday, May 3, 2010
Download speed through apt-cacher and dependency problem with downloading so many packages at a time

hi,
I am not able to stop experimenting with ubuntu lucid lynx the time I installed it.With the apt-cacher,it's easy to download all the packages that you like.So,I was there with synaptic package manager and kept on selecting large number of packages.Finally I got a collection of 148 packages with 220 MB size.When I started to download,I saw variation of speed which is very common but I would like to point it out by some snap-shots.
1st picture shows the usual speed of download through apt-cacher which is 347 KB/s.2nd one shows unusual high speed 2843 KB/s.

But sometime we suffer low speed also.Just like this.

Now,apart from speed,there is one more thing that I would like to share.Since I selected a lot of packages and started downloading all,I got some installation problem.All the packages were downloaded but couldn't be installed properly.Very less packages were installed because of dependency problem.No idea how did it happen.Probably,when there is a huge number of packages ,some of them might have dependency due to others files in the download list.So,in my view,large number of packages should not be installed at a time.
By the way, I sent these dependencies report to developers officially.Here is one screen-shot which explains it.

Conclusion :- try installing less number of packages at a time.
Saturday, May 1, 2010
performance review of ubuntu 10.04 lucid lynx
hello friends,
Ubuntu launched its Final release of lucid lynx 10.04 just 2 days before and I couldn't stop trying it as soon as I could.Reason is not that I was waiting eagerly for its final release.Real reason is that I had done some mistake in hard disk partition while installing slackware which caused me loss of linuxmint which I was using for a very long time.So, finally I thought to try fresh and final release of 10.04.
oh boy,What an OS.Surprisingly it can be called as the perfect OS.Lookwise,it has got better.Also,the most exciting feature is its boot time.Amazing boot time must have impressed everyone.Shutdown time is also faster.This has got attention of some people who are claiming that skipping disk check can also reduce boot time.Anyway,I don't want to create any controversy here.
Talking about look,It gives a sight of mac.The minimize, maximize and close buttons of window is on the left side which gives you feeling of working on mac.Anyway that feature was available previously also but not as default(a package "mac4lin" changes the look in that manner).New Gwibber social client is also very exciting.Gwibber can be configured to broadcast status on facebook,twitter etc. and to see other's status.
Recently "ubuntu tweak" became my latest crush as It has got nice and sexy packages which synaptic package manager didn't let me try directly.visit ubuntu-tweak.com for more info about tweak.As I am in a university which does not provide with a superfast internet connection but allows downloading packages with apt-cacher,I couldn't stop downloading all the packages which caught my attention.Well,It's definitely wastage of resource.
In final words,ubuntu 10.04 is just lovable and awesome and great experience so far.Don't know how soon the bugs will come out.Till then,enjoy lucid lynx.Happy open source.
Ubuntu launched its Final release of lucid lynx 10.04 just 2 days before and I couldn't stop trying it as soon as I could.Reason is not that I was waiting eagerly for its final release.Real reason is that I had done some mistake in hard disk partition while installing slackware which caused me loss of linuxmint which I was using for a very long time.So, finally I thought to try fresh and final release of 10.04.
oh boy,What an OS.Surprisingly it can be called as the perfect OS.Lookwise,it has got better.Also,the most exciting feature is its boot time.Amazing boot time must have impressed everyone.Shutdown time is also faster.This has got attention of some people who are claiming that skipping disk check can also reduce boot time.Anyway,I don't want to create any controversy here.
Talking about look,It gives a sight of mac.The minimize, maximize and close buttons of window is on the left side which gives you feeling of working on mac.Anyway that feature was available previously also but not as default(a package "mac4lin" changes the look in that manner).New Gwibber social client is also very exciting.Gwibber can be configured to broadcast status on facebook,twitter etc. and to see other's status.
Recently "ubuntu tweak" became my latest crush as It has got nice and sexy packages which synaptic package manager didn't let me try directly.visit ubuntu-tweak.com for more info about tweak.As I am in a university which does not provide with a superfast internet connection but allows downloading packages with apt-cacher,I couldn't stop downloading all the packages which caught my attention.Well,It's definitely wastage of resource.
In final words,ubuntu 10.04 is just lovable and awesome and great experience so far.Don't know how soon the bugs will come out.Till then,enjoy lucid lynx.Happy open source.
Thursday, July 23, 2009
symbolic link(linux) Virus Incident
hello friends,
today I would like to discuss a very simple topic related to linux and how it bothered me.recently I was working with linux trying to learn "symbolic links".Symbolic link is a special file which points to another file in the system.it is similar to shortcut in windows.
if you give the command ls -l in your terminal then you can view link files.if output starts with l then it's symbolic link.now,to create a symbolic link we have to use "ln" command with -s option."ln" is for link and "-s" is for symbolic option.syntex is like this ln -s source destination.
now, source means the path of file or directory where it originally is. and destination means the path where you want the link to be.you have to specify the name of link and this should not exist in system otherwise it will give error.
But I did something which I forgot later.I made a symbolic link by typing this ln -s /home/gaurav /home/gaurav/h. since every file of linux was in "gaurav" folder ,when i went in "h" folder inside "gaurav",i found all the files again in this folder including "h".when i again double-clicked "h" it took me to same folder which contained all files including "h".I didn't remember about symbolic links and instantly I was worried that there is some virus in my system.I had heard earlier that there is a virus which creates a folder in each folder including itself.
after some days when I opened shell and typed ls -l, I found "h" showing l which means it's a link only.then i was relieved and deleted this. then I typed ln -s /home/gaurav/videos/jal.mp4 /home/gaurav/Desktop/jal. by this I am able to view this video directly through desktop. I need not go anywhere.and this is done without copying the video or without "cut and paste" from its original destination.
this was a new thing for me.so, I thought it would be good to share this.May be someone new like me would get help from this.But , if you are master of shell, you may laugh at me.
thanks everybody to read this post.
today I would like to discuss a very simple topic related to linux and how it bothered me.recently I was working with linux trying to learn "symbolic links".Symbolic link is a special file which points to another file in the system.it is similar to shortcut in windows.
if you give the command ls -l in your terminal then you can view link files.if output starts with l then it's symbolic link.now,to create a symbolic link we have to use "ln" command with -s option."ln" is for link and "-s" is for symbolic option.syntex is like this ln -s source destination.
now, source means the path of file or directory where it originally is. and destination means the path where you want the link to be.you have to specify the name of link and this should not exist in system otherwise it will give error.
But I did something which I forgot later.I made a symbolic link by typing this ln -s /home/gaurav /home/gaurav/h. since every file of linux was in "gaurav" folder ,when i went in "h" folder inside "gaurav",i found all the files again in this folder including "h".when i again double-clicked "h" it took me to same folder which contained all files including "h".I didn't remember about symbolic links and instantly I was worried that there is some virus in my system.I had heard earlier that there is a virus which creates a folder in each folder including itself.
after some days when I opened shell and typed ls -l, I found "h" showing l which means it's a link only.then i was relieved and deleted this. then I typed ln -s /home/gaurav/videos/jal.mp4 /home/gaurav/Desktop/jal. by this I am able to view this video directly through desktop. I need not go anywhere.and this is done without copying the video or without "cut and paste" from its original destination.
this was a new thing for me.so, I thought it would be good to share this.May be someone new like me would get help from this.But , if you are master of shell, you may laugh at me.
thanks everybody to read this post.
Labels:
BITS,
linux,
shell,
symbolic link
Subscribe to:
Posts (Atom)