I just messed up with ~/.profile, tried to add something to PATH, but looks like there was a syntax error in my code and now the login screen functionality won't work and I can use ctrlshiftf1 tty to login but essential commands such as sudo and ls won't work because ~/.profile is broken. How can I fix that ?

  • That is how the standard ~/.profile file looks like. – Videonauth May 2 '16 at 16:34
  • ok how can i modify profile? to make it like the link – moein rahimi May 2 '16 at 16:36
  • not sure if you can delete .profile and have it recreate .. you could try tty1 and try cp ~/.profile ~/.profile.bak then rm ~/.profile that may at least let you get to a place where you can edit the original and fix the problem – John Orion May 2 '16 at 16:38

You can first try to just copy the default .profile from the original copy found in /etc/skel/:

First, it is recommended to make a backup of your profile first just in case (Thank you wjandrea):

/bin/cp ~/.profile{,.bak}

Then you can copy the default from the /etc/skel

/bin/cp /etc/skel/.profile /home/<username>/

If for some reason that does not work, you can follow the next part to replace your .profile from its original contents:

Boot your system to Recovery Mode first so that you have root capabilities to your system.

A .profile file is stored in the /etc/skel/ directory that you can copy to your home folder.

cp /etc/skel/.profile /home/<username>/

then set the permissions and ownership on the file so it matches your username:

chmod 600 /home/<username>/.profile
chown <username>:<username> /home/<username>/.profile

replacing <username> with your username that you created.

Hope this helps!

  • 1
    You should be able to cp the file without recovery mode by using the complete path /bin/cp. – Jakob Lenfers May 2 '16 at 17:18
  • @JakobLenfers Good point. I will add that to my answer. I will leave the recovery mode just in case someone may not know paths where utilities are located. =) – Terrance May 2 '16 at 17:24

once the same thing happened to me and I could not use recovery mode because it was read-only although you can change it to read-write I didn't know how to do so.

if you have physical access you can create a Linux bootable USB flash and use it to edit the broken file (.profile) in Your installed Linux. just remember to use sudo command so there will be no permission problem.

after you have booted a Linux OS using a USB flash you can find multiple partitions with this filename:


depending on which partition contains your broken file, you have to mount that partition using this command:

sudo mount /dev/sda<number> /media/<current_username>/new_created_directory

don't forget to make new_created_directory using mkdir command before mounting:

mkdir /media/<current_username>/new_created_directory

now for the last step edit the broken file using a text editor for example nano:

nano /media/<current_username>/new_created_directory/home/<broken_os_username>/.profile

now you are all set. restart the computer and unplug the bootable USB flash. you can also do this steps using graphical interface

  • 2
    Please edit the answer to add details about how exactly to accomplish this. Thanks, and welcome to Ask Ubuntu! – wjandrea Aug 12 '18 at 20:46
  • Was your answer based off my answer above? In the Recovery Mode I linked in my answer it says on step 8 to remount the drive as read write with mount -o remount,rw /. Did you miss that step? – Terrance Aug 13 '18 at 17:15
  • @Terrance Unfortunately, I didn't read the link about Recovery mode in your answer. I used the graphical interface using a bootable USB flash but later I updated my answer about how to do it using the terminal and without using recovery mode – farshad hasanpour Aug 16 '18 at 22:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.