install: a file with its permissions from the start

Contents
What the command does
Why not just vi the file
The same in two commands
The folder must exist
Check the result

What the command does

install -m 600 /dev/null ~/.config/opencode-agent/openrouter.key

It creates an empty file that only you can read and write, before any key is in it.

PartMeaning
installA command from GNU coreutils that copies a file and sets its permissions in the same step
-m 600The permissions (mode) of the new file. In octal, 6 = read + write for you, the first 0 = nothing for your group, the last 0 = nothing for other users
/dev/nullA special file that always reads as empty, so the copy is an empty file
~/.config/opencode-agent/openrouter.keyWhere the new file goes

Why not just vi the file

On Ubuntu 24.04 the default for new files makes them readable by everyone. umask shows the default:

umask

0002

The same empty file made both ways:

touch plain.key

install -m 600 /dev/null safe.key

ls -l plain.key safe.key

-rw-rw-r-- 1 me me 0 Oct 27 15:46 plain.key -rw------- 1 me me 0 Oct 27 15:46 safe.key

If you open a new file with vi, paste a key and save, it gets -rw-rw-r--: any other user on the computer can read the key. When vi saves into an existing file, it keeps that file's permissions. So create the file as -rw------- first, then paste the key into it.

The same in two commands

touch ~/.config/opencode-agent/openrouter.key

chmod 600 ~/.config/opencode-agent/openrouter.key

The folder must exist

install does not create the folder, so make it first:

mkdir -p ~/.config/opencode-agent

This is how the key file is made in OpenCode in Docker.

Check the result

ls -l ~/.config/opencode-agent/openrouter.key

The line should start with -rw-------.

Article author: Klavdiya Kondakova

Related articles
Linux
install: a file with its permissions from the start
Files
OpenCode in Docker on Ubuntu 24.04: a safe setup step by step

Search this site

Channel @aofeed Chat @aofeedchat

Contacts and cooperation:
I recommend our hosting beget.com
Write to info@aredel.com if you:
1. Want to write an article for our site or translate an article into your native language.
2. Want to place thematically relevant ads on the site.
3. Ads on my site pass maximum censorship. If you see an ad block unsuitable for school-age children, shocking or misleading - please contact us by e-mail
4. Found a mistake, inaccuracy, bug, etc. on the site. ... .......
5. Articles can be shared on social media by clicking a network icon: