Skip to content

Instantly share code, notes, and snippets.

@DiyRex
Created June 24, 2024 10:02
Show Gist options
  • Save DiyRex/86999cac5d0d3cfef70c68b2071aebdc to your computer and use it in GitHub Desktop.
Save DiyRex/86999cac5d0d3cfef70c68b2071aebdc to your computer and use it in GitHub Desktop.
Deploy VS Code Server in Localhost
#!/bin/bash
# Variables (Change with your preferences)
USER="yourusername"
PASSWORD="yourpassword"
PORT=4500
# Check if the script is run as root
if [ "$(id -u)" -ne 0 ]; then
echo "Please run this script as root."
exit 1
fi
# Download and install the latest Code Server
echo "Downloading and installing Code Server..."
curl -fsSL https://code-server.dev/install.sh | sh
# Create systemd service file
echo "Creating systemd service file..."
SERVICE_FILE="/etc/systemd/system/code-server.service"
cat <<EOF > $SERVICE_FILE
[Unit]
Description=Code Server
After=network.target
[Service]
Type=simple
User=$USER
ExecStart=/usr/local/bin/code-server --bind-addr 0.0.0.0:$PORT --auth password --password $PASSWORD
Restart=always
Environment=PATH=/usr/local/bin:/usr/bin:/bin
[Install]
WantedBy=multi-user.target
EOF
# Reload systemd and enable the service
echo "Reloading systemd and enabling Code Server service..."
systemctl daemon-reload
systemctl enable code-server
# Start the Code Server service
echo "Starting Code Server service..."
systemctl start code-server
# Check the status of the service
echo "Checking Code Server service status..."
systemctl status code-server
echo "Code Server installation and setup complete. Access it at http://localhost:$PORT"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment