| Server IP : 185.11.201.71 / Your IP : 192.168.7.18 Web Server : Apache/2.4.29 (Ubuntu) System : Linux tech-virtual-machine 4.15.0-213-generic #224-Ubuntu SMP Mon Jun 19 13:30:12 UTC 2023 x86_64 User : tech ( 1000) PHP Version : 7.4.28 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, MySQL : OFF | cURL : OFF | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /snap/core24/1643/usr/share/subiquity/ |
Upload File : |
#!/bin/bash
pretty_name="$( awk -F "=" '$1 = /PRETTY_NAME/ {print $2;}' /usr/lib/os-release | sed 's/"//g')"
tty_name=$(tty | cut -c 6-)
get_first_ip() {
local ip_address
for iface in $(ip -br address | awk '{print $1}')
do
if [ -n "${iface}" ] && [ "${iface}" != "lo" ] && ip addr show dev "${iface}" >/dev/null 2>&1; then
ip_address="$(ip -4 -br addr show dev "${iface}" | awk '{print$3}' | sed 's|\(.*\)/.*|\1|')"
if [ -n "${ip_address}" ]; then
echo "${ip_address}"
return 0
fi
fi
done
echo "<no ip address>"
return 2
}
print_ssh_commands() {
local user_name
# take any user with non zero authorized keys file
for h in $(getent passwd | grep -v -e /nologin -e /false | cut -d: -f6 | grep -e /home -e /root)
do
if [ ! -s "${h}/.ssh/authorized_keys" ]; then
continue
fi
user_name="$(basename "${h}")"
for iface in $(ip -br address | awk '$2 == "UP" {print $1}')
do
if [ -n "${iface}" ] && [ "${iface}" != "lo" ] && ip addr show dev "${iface}" >/dev/null 2>&1; then
ip4_address="$(ip -4 -br addr show dev "${iface}" | awk '{print$3}' | sed 's|\(.*\)/.*|\1|')"
ip6_address="$(ip -6 -br addr show dev "${iface}" | awk '{print$3}' | sed 's|\(.*\)/.*|\1|')"
if [ -n "${ip4_address}" ]; then
printf "\tssh %s@%s\n" "${user_name}" "${ip4_address}"
printf "\tssh %s@%s\n" "${user_name}" "${ip6_address}"
fi
fi
done
echo ""
done
}
print_sshd_finger_prints() {
(
shopt -s nullglob
for key in /etc/ssh/*.pub; do
ssh-keygen -lf "${key}" | awk '{print "\t"substr($4,2,length($4)-2)"\t"$2}'
done
)
return 0
}
write_login_details() {
ip=$(get_first_ip)
local ret=${?}
echo "${pretty_name} on ${ip} (${tty_name})"
echo ""
print_sshd_finger_prints
echo ""
echo "To login:"
echo ""
print_ssh_commands
echo "Personalize your account at https://login.ubuntu.com."
return ${ret}
}
write_login() {
# handle unmanaged devices
local ret=0
# fish for non-root users
# shellcheck disable=SC2143
if [ -z "$(getent passwd | grep -v -e /nologin -e /false | grep /home)" ]; then
ip=$(get_first_ip)
if [ -n "${ip}" ]; then
echo "device managed without user @ ${ip}"
else
echo "device managed without user"
fi
else
write_login_details
ret=${?}
fi
return ${ret}
}
case ${1} in
--host-fingerprints)
print_sshd_finger_prints
;;
*)
write_login
;;
esac
# pass on return code
exit ${?}