Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What if Ubuntu16.04 cannot switch root permissions?

2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

Editor to share with you what to do if Ubuntu16.04 cannot switch root permissions. I hope you will get something after reading this article. Let's discuss it together.

Find a problem

Found that you could not switch to root permissions during su root. Display: / usr/local/bin/zsh has 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. I didn't feel as good as bash for a while (purely personal feeling), so sudo apt remove zsh.

The default shell was changed to zsh at that time:

Chsh-s / bin/zsh

So what exactly did chsh change? Chsh-s actually modifies the line in your / etc/passwd file that corresponds to your user name, which we can check:

Shanlei@shanlei-Lenovo-ideapad-110-15ISK etc/passwd $cat / etc/passwd | grep ^ ISK-15ISK etc/passwd $

Solution method

Enter passwd:

Sudo vim / etc/passwd

We can see:

Root:x:0:0:root:/root:/usr/local/bin/zshdaemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologinbin:x:2:2:bin:/bin:/usr/sbin/nologinsys:x:3:3:sys:/dev:/usr/sbin/nologinsync:x:4:65534:sync:/bin:/bin/syncgames:x:5:60:games:/usr/games:/usr/sbin/nologinman:x:6:12: Man:/var/cache/man:/usr/sbin/nologinlp:x:7:7:lp:/var/spool/lpd:/usr/sbin/nologinmail:x:8:8:mail:/var/mail:/usr/sbin/nologinnews:x:9:9:news:/var/spool/news:/usr/sbin/nologinuucp:x:10:10:uucp:/var/spool/uucp:/usr/sbin/nologinproxy:x:13:13:proxy:/bin:/usr/sbin/nologinwww- Data:x:33:33:www-data:/var/www:/usr/sbin/nologinbackup:x:34:34:backup:/var/backups:/usr/sbin/nologinlist:x:38:38:Mailing List Manager:/var/list:/usr/sbin/nologinirc:x:39:39:ircd:/var/run/ircd:/usr/sbin/nologingnats:x:41:41:Gnats Bug-Reporting System (admin): / var/lib/gnats:/usr/sbin/nologinnobody:x:65534 : 65534:nobody:/nonexistent:/usr/sbin/nologinsystemd-timesync:x:100:102:systemd Time Synchronization ,: / run/systemd:/bin/falsesystemd-network:x:101:103:systemd Network Management,:/run/systemd/netif:/bin/falsesystemd-resolve:x:102:104:systemd Resolver,:/run/systemd/resolve:/bin/falsesystemd-bus-proxy:x:103:105:systemd Bus Proxy : / run/systemd:/bin/falsesyslog:x:104:108::/home/syslog:/bin/false_apt:x:105:65534::/nonexistent:/bin/falsemessagebus:x:106:110::/var/run/dbus:/bin/falseuuidd:x:107:111::/run/uuidd:/bin/falselightdm:x:108:114:Light Display Manager:/var/lib/lightdm:/bin/falsewhoopsie:x:109:116::/nonexistent:/bin/falseavahi-autoipd:x:110:119:Avahi autoip daemon : / var/lib/avahi-autoipd:/bin/falseavahi:x:111:120:Avahi mDNS daemon,:/var/run/avahi-daemon:/bin/falsednsmasq:x:112:65534:dnsmasq,:/var/lib/misc:/bin/falsecolord:x:113:123:colord colour management daemon,:/var/lib/colord:/bin/falsespeech-dispatcher:x:114:29:Speech Dispatcher,:/var/run/speech-dispatcher:/bin/falsehplip:x:115:7:HPLIP system user : / var/run/hplip:/bin/falsekernoops:x:116:65534:Kernel Oops Tracking Daemon,:/:/bin/falsepulse:x:117:124:PulseAudio daemon,:/var/run/pulse:/bin/falsertkit:x:118:126:RealtimeKit,:/proc:/bin/falsesaned:x:119:127::/var/lib/saned:/bin/falseusbmux:x:120:46:usbmux daemon,:/var/lib/usbmux:/bin/falseshanlei: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:

The / usr/local/bin/bash in the first line is changed to / usr/local/bin/zsh, which is for the root user:

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

Change the / bin/bash on the last line to / bin/zsh, which should consist of the login user name and computer name of each computer:

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

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

Check the bash installation location:

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

Find that the execution file of bash is in / bin/bash, so modify the first line of / etc/passwd file again:

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 root@shanlei-Lenovo-ideapad-110 15ISK:~# $su-password:

Success ~

-Beautiful dividing line-

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

Ln-s: force the soft link of / bin/sh to bash: sudo ln-s / bin/bash / bin/sh

Dpkg-reconfigure dash: this method is recommended in Ubuntu: sudo dpkg-reconfigure dash, a pop-up option, set "dash as the default shell" and select no.

How do I check what shell is installed on my machine?

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

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

Shanlei@shanlei-Lenovo-ideapad-110-15ISKVOR $echo $SHELL/bin/bashshanlei@shanlei-Lenovo-ideapad-110-15ISKRV $

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, while the bash or zsh we use only starts a bash or zsh interpreter program and does not change the environment. If you want to change the environment, you must use chsh.

After reading this article, I believe you have a certain understanding of "Ubuntu16.04 can not switch root permissions". If you want to know more about it, you are welcome to follow the industry information channel. Thank you for reading!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report