Accidentally deleted symlink libc.so.6 in CentOS 6.4. How to get sudo privilege to re-create it?
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~
Solution 1:
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.