Accidentally deleted symlink libc.so.6 in CentOS 6.4. How to get sudo privilege to re-create it?

6,266

The best thing to do in this case by far is to boot the server using a livecd, mount the applicable partitions, and create the symlink (be careful that the symlink points to exactly the right place when doing this, as if it points to a different absolute path than when you are running, it will not be helpful).

I can't think of a program you can run which will not require libc, nor a way to modify root's environment without root (by design the latter is impossible).

Also, you should really unbind the macro key which has sudo rm /lib64/libc.so.6, enter, your password, and enter bound to it. I can think of only a few more inconvenient accidental keypresses.

However, as a last ditch attempt, try using su with no options, which preserves most of your environment and sets your UID to root.

You may also be able to create the symlink in the current working directory and run things, though this doesn't always work.

Share:
6,266

Related videos on Youtube

kangshiyin
Author by

kangshiyin

Updated on September 18, 2022

Comments

  • kangshiyin
    kangshiyin over 1 year

    I accidentally deleted the symbol link /lib64/libc.so.6 -> /lib64/libc-2.12.so with

    $ sudo rm libc.so.6
    

    Then I can not use anything including ls command. The error appears for any command I type

    ls: error while loading shared libraries: libc.so.6: cannot open shared object file: No such file or directory
    

    I've tried

    $ export LD_PRELOAD=/lib64/libc-2.12.so
    

    After this I can use ls and ln ..., but still can not use sudo ln ..., sudo -E ln ..., sudo su or even su. I always get this err

    sudo: error while loading shared libraries: libc.so.6: cannot open shared object file: No such file or directory
    

    or

    su: error while loading shared libraries: libc.so.6: cannot open shared object file: No such file or directory
    

    It seems LD_PRELOAD works only for the current shell session of my account, but not for a new account like root or a new session.

    It's a remote server so I can not use a live CD. I now have a ssh bash session alive but can not establish new ones. I have sudo privilege, but don't have root password.

    So currently my problem is I need to run sudo sln -s libc-2.12.so libc.so.6 to re-create the symlink libc.so.6, but I can not run sudo without libc.so.6.

    How can I fix it? Thanks~

    • ALex_hha
      ALex_hha almost 11 years
      which version of kernel do you use?
    • kangshiyin
      kangshiyin almost 11 years
      @ALex_hha 2.6.32-358.6.2.el6.x86_64
    • ALex_hha
      ALex_hha almost 11 years
      Unfortunately, packetstormsecurity.com/files/121616/semtex.c will not work
  • kangshiyin
    kangshiyin almost 11 years
    su does not work either. It seems the only way is to wait until holiday ends and use the live cd. Thanks.
  • Falcon Momot
    Falcon Momot almost 11 years
    Added one more thing I forgot about...
  • kangshiyin
    kangshiyin almost 11 years
    Yes, I found LD_PRELOAD allow me to run most of the applications. but still can not compile c code. It seems gcc and ld need the orignal /lib64/libc.so.6 when compiling.
  • Falcon Momot
    Falcon Momot almost 11 years
    They need it (or a symlink) when linking if the linker links in libc (it does). It also has to be in the linker's library search path (specify with -l).
  • kangshiyin
    kangshiyin almost 11 years
    tried but failed. a lot of external dynamic libs and non-gcc compilers required by my code make things very complicated.
  • Falcon Momot
    Falcon Momot almost 11 years
    Yeah, do the livecd thing then.