New on LowEndTalk? Please Register and read our Community Rules.
All new Registrations are manually reviewed and approved, so a short delay after registration may occur before your account becomes active.
All new Registrations are manually reviewed and approved, so a short delay after registration may occur before your account becomes active.
How to change root password at startup using bash
So I wrote the following bash script debian_startup.sh
to change root password when system boots but it doesn't work.
#!/bin/bash
echo "SomePassword" | passwd --stdin root
I have placed this script in /etc/init.d/debian_startup.sh
and also made it executable by running following command:
chmod 755 /etc/init.d/debian_startup.sh
But when I boot the system, password isn't changed and I can still login using old password. How do I check that the script is actually running on boot or may be there is syntax problem in the script?
Comments
Maybe add it into crontab -e ? under @reboot
https://www.cyberciti.biz/faq/linux-execute-cron-job-after-system-reboot/
Yeah I have seen that I can also use crontab but I want to use init.d first.
It seems I have a syntax error in my script because when I run it directly
./debian_startup.sh
then I get error that stdin is unrecognized.To check if script is running, change it to something simple such as
touch /var/my_script_ran
as for syntax problems - I assume you tested the command from an interactive shell?
any number of potential issues whether or not running at boot time, for example:
I understand that you want to use a script in init.d ...
I'd be interested to know your reason for this preference.
Otherwise might suggest writing a systemd unit as an alternate method
Using
-e
successfully updates password BUT it also expires user account so he has to set password again when logs in. Without specifying -e it doesn't work I wonder why.Following works
Following doesn't work
I use "passwd -l root" to disable the password completely. After installing ssh pubkey of course.
Only said they tossed it in init.d not that they enabled it as a service or anything. It's never running would be my bet.
@alilet - this sort of multi-faceted mystery in general is always a great opportunity to apply some methodological "scientific method" approach to rule out possible explanations
(which you seem to be doing )
alternatively - from a more "hackerly" point of view - it may be the case that ultimately you are just changing a string in a file
(the name of which seems to make cloudflare nervous)
that is, the 'shadow' file, in the '/etc' directory
so that may be another way to do what you need without going through the
passwd
command in your script.it may not be the cleanest method but something to keep in your back pocket if push comes to shove and you just want to get the job done ...
sudo chmod +x /etc/rc.local
sudo systemctl start rc-local
what happens when you try to login on the console?
Not sure, there may be a way to disable the password for a console login. It hasn't come up. On Hetzner I use the rescue system instead of a KVM, some others like DO have a way to reset the password from the client area, hmm. Can also log into a user account (except I lock out the passwords for those too) and "su". In principle I should even lock out ssh except from a jump host, but I don't bother doing that.
Changing root’s shell to /bin/false may give you the same effect, though I haven’t tried it.