|
Server : LiteSpeed System : Linux srv104790275 5.15.0-161-generic #171-Ubuntu SMP Sat Oct 11 08:17:01 UTC 2025 x86_64 User : dewac4139 ( 1077) PHP Version : 8.0.30 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare, Directory : /usr/local/CyberCP/CPScripts/EasyEngine/ |
Upload File : |
#!/bin/bash
# script to set up access key for non-interactive SSH login
check_root() {
if [[ $(id -u) != 0 ]] > /dev/null; then
echo -e "\nYou must use root permission...\n"
exit
fi
}
key_generation() {
rm -f /root/.ssh/cyberpanel_migration_key
rm -f /root/.ssh/cyberpanel_migration_key.pub
ssh-keygen -t rsa -N "" -f /root/.ssh/cyberpanel_migration_key
if [[ -f /root/.ssh/authorized_keys ]] ; then
cp /root/.ssh/authorized_keys /root/.ssh/authorized_keys_migration
string=$(head -c 3 /root/.ssh/authorized_keys)
if [[ $string != "ssh" ]] ; then
#check if it's like AWS that prohibits direct root login.
rm -f /root/.ssh/authorized_keys
cat /root/.ssh/cyberpanel_migration_key.pub > /root/.ssh/authorized_keys
else
cat /root/.ssh/cyberpanel_migration_key.pub >> /root/.ssh/authorized_keys
fi
else
cat /root/.ssh/cyberpanel_migration_key.pub > /root/.ssh/authorized_keys
chmod 600 /root/.ssh/authorized_keys
fi
echo -e "\nsuccessfully set up public key and private key for migration..."
# this function creates public key and private key
}
ssh_config() {
rm -f /etc/ssh/sshd_config_migration
cp /etc/ssh/sshd_config /etc/ssh/sshd_config_migration
if grep -q "#PubkeyAuthentication yes" /etc/ssh/sshd_config ; then
sed -i 's|#PubkeyAuthentication yes|PubkeyAuthentication yes|g' /etc/ssh/sshd_config
fi
systemctl restart sshd
#this function will modify ssh configuration to allow public key login and root login
}
revert_change() {
if [[ ! -f /etc/ssh/sshd_config_migration ]] ; then
echo -e "You didn't enable it..."
exit
else
rm -f /root/.ssh/authorized_keys
rm -f /etc/ssh/sshd_config
rm -f /root/.ssh/cyberpanel_migration_key
rm -f /root/.ssh/cyberpanel_migration_key.pub
cp /etc/ssh/sshd_config_migration /etc/ssh/sshd_config
if [[ -f /root/.ssh/authorized_keys_migration ]] ; then
cp /root/.ssh/authorized_keys_migration /root/.ssh/authorized_keys
rm -f /root/.ssh/authorized_keys_migration
fi
systemctl restart sshd
fi
echo -e "\nsuccessfully removed public key and private key for migration..."
#this function will revert the changes and restore backed up files.
}
check_root
if [[ $1 == "enable" ]] ; then
ssh_config
key_generation
elif [[ $1 == "disable" ]] ; then
revert_change
else
echo -e "\nPlease use argument enable or disable"
echo -e "\ne.g. ./key.sh enable\n"
fi