Ubuntu 16.04 cannot switch root permissions

problem found

When su root, I found that I could not switch to root privileges. Display: /usr/local/bin/zsh No files or directories

After thinking about the problem, I suddenly remembered that I wanted to change the shell theme some time ago, so I installed zsh and oh-my-zsh. After using it for a while, I felt that bash was not easy to use (pure personal feeling), so sudo apt remove zsh Up.

At that time, the default shell was changed to zsh:

chsh -s /bin/zsh

So where did chsh change? chsh -s actually changed the line corresponding to your username in your /etc/passwd file. We can check:

shanlei@shanlei-Lenovo-ideapad-110-15ISK:~$ cat /etc/passwd|grep ^shanlei
shanlei:x:1000:1000:shanlei,,,:/home/shanlei:/bin/zsh
shanlei@shanlei-Lenovo-ideapad-110-15ISK:~$

Solution

Enter passwd:

sudo vim /etc/passwd

We can see that:

root:x:0:0:root:/root:/usr/local/bin/zsh
daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin
bin:x:2:2:bin:/bin:/usr/sbin/nologin
sys:x:3:3:sys:/dev:/usr/sbin/nologin
sync:x:4:65534:sync:/bin:/bin/sync
games:x:5:60:games:/usr/games:/usr/sbin/nologin
man:x:6:12:man:/var/cache/man:/usr/sbin/nologin
lp:x:7:7:lp:/var/spool/lpd:/usr/sbin/nologin
mail:x:8:8:mail:/var/mail:/usr/sbin/nologin
news:x:9:9:news:/var/spool/news:/usr/sbin/nologin
uucp:x:10:10:uucp:/var/spool/uucp:/usr/sbin/nologin
proxy:x:13:13:proxy:/bin:/usr/sbin/nologin
www-data:x:33:33:www-data:/var/www:/usr/sbin/nologin
backup:x:34:34:backup:/var/backups:/usr/sbin/nologin
list:x:38:38:Mailing List Manager:/var/list:/usr/sbin/nologin
irc:x:39:39:ircd:/var/run/ircd:/usr/sbin/nologin
gnats:x:41:41:Gnats Bug-Reporting System(admin):/var/lib/gnats:/usr/sbin/nologin
nobody:x:65534:65534:nobody:/nonexistent:/usr/sbin/nologin
systemd-timesync:x:100:102:systemd Time Synchronization,,,:/run/systemd:/bin/false
systemd-network:x:101:103:systemd Network Management,,,:/run/systemd/netif:/bin/false
systemd-resolve:x:102:104:systemd Resolver,,,:/run/systemd/resolve:/bin/false
systemd-bus-proxy:x:103:105:systemd Bus Proxy,,,:/run/systemd:/bin/false
syslog:x:104:108::/home/syslog:/bin/false
_ apt:x:105:65534::/nonexistent:/bin/false
messagebus:x:106:110::/var/run/dbus:/bin/false
uuidd:x:107:111::/run/uuidd:/bin/false
lightdm:x:108:114:Light Display Manager:/var/lib/lightdm:/bin/false
whoopsie:x:109:116::/nonexistent:/bin/false
avahi-autoipd:x:110:119:Avahi autoip daemon,,,:/var/lib/avahi-autoipd:/bin/false
avahi:x:111:120:Avahi mDNS daemon,,,:/var/run/avahi-daemon:/bin/false
dnsmasq:x:112:65534:dnsmasq,,,:/var/lib/misc:/bin/false
colord:x:113:123:colord colour management daemon,,,:/var/lib/colord:/bin/false
speech-dispatcher:x:114:29:Speech Dispatcher,,,:/var/run/speech-dispatcher:/bin/false
hplip:x:115:7:HPLIP system user,,,:/var/run/hplip:/bin/false
kernoops:x:116:65534:Kernel Oops Tracking Daemon,,,:/:/bin/false
pulse:x:117:124:PulseAudio daemon,,,:/var/run/pulse:/bin/false
rtkit:x:118:126:RealtimeKit,,,:/proc:/bin/false
saned:x:119:127::/var/lib/saned:/bin/false
usbmux:x:120:46:usbmux daemon,,,:/var/lib/usbmux:/bin/false
shanlei:x:1000:1000:shanlei,,,:/home/shanlei:/bin/zsh

Because what I want is the default bash, I modified the first and last lines of the passwd file:

Change the /usr/local/bin/bash on the first line to /usr/local/bin/zsh, this is for the root user:

root:x:0:0:root:/root:/usr/local/bin/bash

Change the last line of /bin/bash to /bin/zsh, this should be the login user name + computer name of each computer:

shanlei:x:1000:1000:shanlei,,,:/home/shanlei:/bin/bash

Save and exit, restart the shell, switch root permissions, and find that there are no files or directories in /usr/local/bin/bash

Check the bash installation location:

shanlei@shanlei-Lenovo-ideapad-110-15ISK:~$ whereis bash
bash:/bin/bash /etc/bash.bashrc /usr/share/man/man1/bash.1.gz
shanlei@shanlei-Lenovo-ideapad-110-15ISK:~$ 

Found that the execution file of bash is in /bin/bash, so I re-modified the first line of the /etc/passwd file:

root:x:0:0:root:/root:/bin/bash

Then change the default shell to bash:

chsh -s /bin/bash

Switch again:

shanlei@shanlei-Lenovo-ideapad-110-15ISK:~$ su -
password:
root@shanlei-Lenovo-ideapad-110-15ISK:~# 

Success~

——– Beautiful dividing line——–

There are two other ways to modify the default shell of ubuntu:

How can I check which shells are installed on my machine?

shanlei@shanlei-Lenovo-ideapad-110-15ISK:~$ cat /etc/shells
# /etc/shells: valid login shells
/bin/sh
/bin/dash
/bin/bash
/bin/rbash
shanlei@shanlei-Lenovo-ideapad-110-15ISK:~$

How can I check which shell I am currently using? (Note that SHELL must be capitalized!)

shanlei@shanlei-Lenovo-ideapad-110-15ISK:~$ echo $SHELL
/bin/bash
shanlei@shanlei-Lenovo-ideapad-110-15ISK:~$ 

After executing zsh, I check that the current shell type is still /bin/bash?

The current shell is a big environment for a logged-in user, and the bash or zsh we use only starts a bash or zsh interpreter program, and does not change the big environment. If you want to change the big environment , Must use chsh

to sum up

The above is the entire content of this article. I hope that the content of this article has a certain reference value for your study or work. If you have any questions, you can leave a message and exchange. Thank you for your support to ZaLou.Cn.

Recommended Posts

Ubuntu 16.04 cannot switch root permissions
Ubuntu18.04 switch Python version
Ubuntu16.04 switch python version
ubuntu root default password (initial password)
Linux basics (root privileges in Ubuntu)