You are not logged in.

#1 2013-06-12 06:12:10

Konstantin_hu
Banned
Registered: 2012-05-14
Posts: 84
Website

Where should I store my bash scripts?

Hi!

In which directory should I store securely my own bash (and Ruby, Python) scripts? Some of them contain passwords too, for example which uploads files to an FTP server. Is it secure to store them in /usr/local/bin? What chmod setting should I apply on them? 755?

Offline

#2 2013-06-12 06:47:24

cookies
Member
Registered: 2013-01-17
Posts: 253

Re: Where should I store my bash scripts?

I added ~/bin to my path and put my scripts there. As long as you are the only one using those scripts you should be fine with ~/bin. If other users need to use some of those scripts, too, /usr/local/bin might be a better location those.

Konstantin_hu wrote:

Some of them contain passwords too, for example which uploads files to an FTP server. Is it secure to store them in /usr/local/bin? What chmod setting should I apply on them? 755?

Setting permissions to 755 makes the files world-readable, which is a very bad idea in that case, http://www.tuxfiles.org/linuxhelp/filepermissions.html

Offline

#3 2013-06-12 07:58:23

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: Where should I store my bash scripts?

I think the most often location I came across are

export PATH="$PATH:/usr/local/bin/"

or

export PATH="${PATH}:${HOME}/bin"

Offline

#4 2013-06-12 08:42:46

SanskritFritz
Member
From: Budapest, Hungary
Registered: 2009-01-08
Posts: 1,954
Website

Re: Where should I store my bash scripts?

Scripts like yours should be encrypted because if your computer gets stolen, all data on the harddisk will be accessible regardless of permissions. I recommend to encypt the ~/bin directory with encfs. Of course that means you will have to enter the password at every boot (or login for that matter).


zʇıɹɟʇıɹʞsuɐs AUR || Cycling in Budapest with a helmet camera || Revised log levels proposal: "FYI" "WTF" and "OMG" (John Barnette)

Offline

#5 2013-06-12 23:22:40

cfr
Member
From: Cymru
Registered: 2011-11-27
Posts: 7,168

Re: Where should I store my bash scripts?

Putting passwords in scripts in clear text strikes me as a bad idea even if you do encrypt your disk or include them in an encrypted container. But perhaps my feeling that this is opening security holes is merely a feeling...

Of course, it depends on what the passwords are for. There are things I have passwords for where it wouldn't bother me but those are passwords I'm not worried about being exposed.


CLI Paste | How To Ask Questions

Arch Linux | x86_64 | GPT | EFI boot | refind | stub loader | systemd | LVM2 on LUKS
Lenovo x270 | Intel(R) Core(TM) i5-7200U CPU @ 2.50GHz | Intel Wireless 8265/8275 | US keyboard w/ Euro | 512G NVMe INTEL SSDPEKKF512G7L

Offline

#6 2013-06-12 23:26:16

WonderWoofy
Member
From: Los Gatos, CA
Registered: 2012-05-19
Posts: 8,414

Re: Where should I store my bash scripts?

karol wrote:

I think the most often location I came across are

export PATH="$PATH:/usr/local/bin/"

or

export PATH="${PATH}:${HOME}/bin"

@karol, this will effectively make your PATH="/usr/local/sbin:/usr/local/bin:/usr/bin:/usr/local/bin" as the /usr/local directory is already set up to override anything in /usr/bin anyway.

% grep PATH /etc/profile
PATH="/usr/local/sbin:/usr/local/bin:/usr/bin"

Offline

#7 2013-06-12 23:36:46

progandy
Member
Registered: 2012-05-17
Posts: 5,307

Re: Where should I store my bash scripts?

If you need to store the password relatively secure, do this:
- data file in encrypted partition to store password. (only root has read access)
- wrapper executable using suid (only root can modify it)
- shellscript (only root can modify it)
> wrapper runs as root, opens data file, drops privileges, executes hardcoded bash script, script reads file.


| alias CUTF='LANG=en_XX.UTF-8@POSIX ' | alias ENGLISH='LANG=C.UTF-8 ' |

Offline

#8 2013-06-12 23:38:52

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: Where should I store my bash scripts?

WonderWoofy wrote:
karol wrote:

I think the most often location I came across are

export PATH="$PATH:/usr/local/bin/"

or

export PATH="${PATH}:${HOME}/bin"

@karol, this will effectively make your PATH="/usr/local/sbin:/usr/local/bin:/usr/bin:/usr/local/bin" as the /usr/local directory is already set up to override anything in /usr/bin anyway.

% grep PATH /etc/profile
PATH="/usr/local/sbin:/usr/local/bin:/usr/bin"

Good point. I was looking over some old notes when this thread came up and it didn't occur to me check the facts first.
Typically me ;P

Offline

#9 2013-06-12 23:51:13

firecat53
Member
From: Lake Stevens, WA, USA
Registered: 2007-05-14
Posts: 1,542
Website

Re: Where should I store my bash scripts?

I believe the XDG spec (and Python PEP 370, if you care) also allow use of directories under ~/.local/{bin, lib, var, share} . This is what I prefer, as it keeps my $HOME a little cleaner.

Scott

Offline

#10 2013-06-13 00:30:09

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 30,456
Website

Re: Where should I store my bash scripts?

I used to have a ~/bin, but after a while most of the items in it had spent their early days in ~/code, so eventually I moved ~/bin to ~/code/bin and added only the last one to my path.  I have several small tools there that I've just never bothered to make PKGBUILDS for.


"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman

Offline

#11 2013-06-30 22:08:49

ayekat
Member
Registered: 2011-01-17
Posts: 1,632

Re: Where should I store my bash scripts?

firecat53 wrote:

I believe the XDG spec (and Python PEP 370, if you care) also allow use of directories under ~/.local/{bin, lib, var, share} . This is what I prefer, as it keeps my $HOME a little cleaner.

I didn't know that this was specified by XDG (thanks!). But anyway, I also keep my scripts in ~/.local/bin, as it doesn't clutter up my home folder.
For passwords... I usually try to avoid passwords in files, and otherwise they are at least never too critical (lastfm account password in mpdscribble config, for example). I just try to be careful with permissions.


pkgshackscfgblag

Offline

#12 2013-06-30 22:13:32

Roken
Member
From: South Wales, UK
Registered: 2012-01-16
Posts: 1,340

Re: Where should I store my bash scripts?

I use ~/scripts and have it added to my path. That way, I can never confuse my own scripts with installed programs. I guess I could use /opt/scripts or something similar to stay closer to the definition, but it wouldn't change things, and keeping them in ~/ means I can edit without root.


Ryzen 5900X 12 core/24 thread - RTX 3090 FE 24 Gb, Asus B550-F Gaming MB, 128Gb Corsair DDR4, Cooler Master N300 chassis, 5 HD (2 NvME PCI, 4SSD) + 1 x optical.
Linux user #545703

/ is the root of all problems.

Offline

Board footer

Powered by FluxBB