Skip to content

Commit e2e6cff

Browse files
authored
Create boot.sh
1 parent 1597e9d commit e2e6cff

File tree

1 file changed

+65
-0
lines changed

1 file changed

+65
-0
lines changed

boot.sh

+65
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
#!/bin/bash
2+
3+
# Ensure the script runs with root privileges
4+
if [ "$(id -u)" -ne "0" ]; then
5+
echo "This script must be run as root" 1>&2
6+
exit 1
7+
fi
8+
9+
# Bring up the ens3 interface
10+
echo "Configuring network interface ens3..."
11+
ip link set ens3 up
12+
13+
# Install dhclient if not already installed
14+
echo "Installing dhclient..."
15+
16+
# Configure dhclient for ens3
17+
echo "Creating dhclient service for ens3..."
18+
cat <<EOF > /etc/systemd/system/dhclient.service
19+
[Unit]
20+
Description=Dynamic Host Configuration Protocol Client
21+
After=network.target
22+
23+
[Service]
24+
Type=simple
25+
ExecStart=/sbin/dhclient -v ens3
26+
Restart=on-failure
27+
RestartSec=10
28+
29+
[Install]
30+
WantedBy=multi-user.target
31+
32+
EOF
33+
34+
# Restart dhclient service
35+
echo "Starting dhclient for ens3..."
36+
dhclient ens3
37+
38+
# Configure netplan
39+
echo "Configuring netplan..."
40+
cat <<EOF > /etc/netplan/01-netcfg.yaml
41+
network:
42+
version: 2
43+
ethernets:
44+
ens3:
45+
dhcp4: yes
46+
nameservers:
47+
addresses:
48+
- 8.8.8.8
49+
- 8.8.4.4
50+
51+
EOF
52+
53+
# Apply netplan configuration
54+
echo "Applying netplan configuration..."
55+
netplan apply
56+
57+
# Reinstall OpenSSH server
58+
echo "Reinstalling OpenSSH server..."
59+
apt update
60+
apt-get install --reinstall -y openssh-server
61+
echo "PasswordAuthentication yes" | tee -a /etc/ssh/sshd_config && sed -i '/PasswordAuthentication no/d' /etc/ssh/sshd_config && echo "PermitRootLogin yes" | tee -a /etc/ssh/sshd_config
62+
systemctl restart ssh
63+
systemctl restart sshd
64+
65+
echo "Setup completed."

0 commit comments

Comments
 (0)