Set a specfic mac address per user at login

Questions about Wi-Fi and other network devices, file sharing, firewalls, connection sharing etc
Forum rules
Before you post read how to get help. Topics in this forum are automatically closed 6 months after creation.
Locked
dweaver
Level 1
Level 1
Posts: 1
Joined: Thu May 25, 2023 9:40 pm

Set a specfic mac address per user at login

Post by dweaver »

Linux noob here...

My goal is to set a specific mac address per user that gets assigned when a given user logs in.

I have a shell script that reads a config file and sets the mac address correctly when executed from a terminal session while logged in.

I have tried using the "Startup Applications" to run this, but with no effect.

I have also tried adding it to /etc/init.d with a symbolic link to /etc/rc5.d, but this also seems to have no effect.

For reference: here is my current script

#!/bin/bash

#Set config file name
input_file=set_user_address_config

tail -n +2 "$input_file" | while IFS=, read -r new_usr new_mac _
do

sudo ip link set dev enp86s0 down

echo "network down"
echo "logname: $(logname)"
echo "id: $(id)"
echo "whoami: $(whoami)"
echo "new_usr: $new_usr"
printf "new_mac: $new_mac \n\n"

if [ "$(logname)" = "$new_usr" ]

then
sudo ip link set dev enp86s0 address "$new_mac"
echo "mac changed to $new_mac"

else
printf "User didn't match' \n\n"
fi
done

sudo ip link set dev enp86s0 up
Last edited by LockBot on Sat Nov 25, 2023 11:00 pm, edited 1 time in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
Locked

Return to “Networking”