You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多
文档控制台
免费开始使用

如何实现Ubuntu用户首次登录时仅运行一次Chrome打开指定网页?

Ubuntu: Auto-Open Chrome to a Specific Page on First Login

Got it, let's break this down step by step. You're spot-on about using /etc/skel—it’s the ideal place to set up default files for new users, and we can build a one-time trigger to make this run only once, just like Unity’s initial help HUD.

Core Idea

We’ll create a script that runs when a new user logs in for the first time, opens Chrome to your target page, then marks itself as "done" so it never runs again. The script and its auto-start trigger will live in /etc/skel so they get copied to every new user’s home directory automatically.

Step 1: Create the One-Time Script

First, make a script in /etc/skel that handles the Chrome launch and self-cleanup:

#!/bin/bash

# Replace this with your target webpage URL
TARGET_URL="https://your-desired-page.com"

# Check if we've already run this script (using a marker file)
if [ ! -f ~/.first_login_completed ]; then
    # Wait a few seconds to let the desktop fully load (adjust if needed)
    sleep 10
    
    # Launch Chrome and navigate to the target URL
    google-chrome-stable "$TARGET_URL" &
    
    # Create a marker file so we don't run again
    touch ~/.first_login_completed
    
    # Delete the auto-start trigger so it doesn't fire on future logins
    rm -f ~/.config/autostart/first_login.desktop
fi

Give the script executable permissions:

sudo chmod +x /etc/skel/first_login_setup.sh

Step 2: Set Up Auto-Start on Login

Next, we need to tell the desktop environment to run this script when the user logs in. Create a .desktop file in /etc/skel/.config/autostart/ (this directory will be copied to the user’s home folder too):

[Desktop Entry]
Type=Application
Name=First Login Chrome Launch
Exec=/home/%USER%/first_login_setup.sh
Hidden=false
NoDisplay=false
X-GNOME-Autostart-enabled=true
Comment=Runs once on first login to open Chrome to a specified page

Note: %USER% will automatically replace with the actual username when the files are copied to the user’s home directory, so the path resolves to ~/first_login_setup.sh correctly.

If you’re using a non-GNOME desktop (like KDE), this .desktop file will still work in most cases—KDE also uses ~/.config/autostart/ for auto-start entries.

Step 3: Test It Out

Create a test user to verify everything works:

sudo adduser testuser

Log in as testuser—after the desktop loads, Chrome should pop up with your target page. Log out and back in, and it won’t run again (the marker file and deleted auto-start entry prevent this).

Quick Notes

  • If Chrome’s executable name isn’t google-chrome-stable on your system, run which google-chrome to find the correct path and update the script.
  • Adjust the sleep 10 value if your desktop takes longer to load—this ensures Chrome doesn’t try to start before the desktop is ready.
  • The marker file ~/.first_login_completed is optional but helpful for debugging; you could also just delete the script itself, but the marker makes it easier to track if the script ran.

内容的提问来源于stack exchange,提问作者Pinguinim

火山引擎 最新活动