Working safely with an AI on the command line
An AI on the command line (Claude Code, for instance) runs real commands on your workstation. You should not run it under your own account, and even less under root. The good practice is to give it its own user account, without sudo, and to share a single directory with it through a common group. The AI can then only reach its home and that shared directory.
The scheme rests on three pieces: a user dedicated to the AI, a shared group, and a setgid directory.
1. Create an account dedicated to the AI
Section titled “1. Create an account dedicated to the AI”Create a normal user (here agent), with no login password and above all without adding it to the sudo group:
adduser --disabled-password --gecos "" agentLogging in to the AI account
Section titled “Logging in to the AI account”Since the account has no password, you log in with an SSH key. ssh-copy-id is of no use here (it would need a password to drop the key), so the public key is installed by hand.
You have to be root (the -o/-g options and chown to another user require it). Put your public key (the one of your workstation, YOUR_USER) into the AI account:
install -d -o agent -g agent -m 700 ~agent/.sshcat /home/YOUR_USER/.ssh/id_ed25519.pub >> ~agent/.ssh/authorized_keyschown agent:agent ~agent/.ssh/authorized_keyschmod 600 ~agent/.ssh/authorized_keysThe connection then needs no password:
ssh agent@localhostTo go faster, create a small ~/bin/agent wrapper:
#!/bin/bashssh agent@localhostMake it executable (755):
chmod 755 ~/bin/agentTo be able to start it by simply typing agent, the ~/bin directory must be in the PATH. Add this line at the end of your ~/.profile (or ~/.bashrc):
export PATH="$HOME/bin:$PATH"Reload the file (or open a new terminal) to apply it:
source ~/.profileYou can now connect with a simple:
agent2. Create the shared group
Section titled “2. Create the shared group”This group is the common ground between you (the developer or the sysadmin) and the AI:
addgroup equipe3. Add the developer and the AI to the group
Section titled “3. Add the developer and the AI to the group”One command per member:
adduser dev equipeadduser agent equipeEach user has to open a new session (or run newgrp equipe) for the group membership to take effect.
Check:
getent group equipeequipe:x:1200:dev,agent4. Create the shared directory with the right permissions
Section titled “4. Create the shared directory with the right permissions”The key point is the setgid bit (the s in the group permissions): every file or directory created inside automatically inherits the equipe group, whoever created it.
mkdir /home/projetchown root:equipe /home/projetchmod 2770 /home/projet2770 reads as:
2: setgid bit (group inheritance on new files);770: the group has read, write and execute; other users have nothing.
Check, the s must appear in place of the group x:
ls -ld /home/projetdrwxrws--- 2 root equipe 4096 juil. 24 10:00 /home/projet5. Check the umask
Section titled “5. Check the umask”Setgid passes on the right group, but not the group write permission: for files created in the shared directory to be editable by the whole group, they must be 664, so the umask must be 002. On Debian that is the default setting. Check:
umaskIt must answer 0002. If it does not, add umask 002 to the ~/.profile of the AI account.
6. Check the result
Section titled “6. Check the result”Logged in as agent (ssh agent@localhost), create a file in the shared directory: it must belong to the equipe group and be writable by the group.
touch /home/projet/test.txtls -l /home/projet/test.txt-rw-rw-r-- 1 agent equipe 0 juil. 24 10:05 /home/projet/test.txtThe group (equipe) does have rw: the developer will be able to edit this file, and the other way round.
Good practices
Section titled “Good practices”- No
sudofor the AI account: it only works in its home and in the shared directory. - One shared directory per project: do not share the whole home of the developer.
- Backup and versioning: keep the work under Git in the shared directory, so you can roll back easily.
