Category: Linux

Linux Cheat Sheet – Users

Create User

useradd --create-home -c "Account to run the something app" something

Eek, reverse it

userdel -r something

SSH Instance Access

Set up an ssh key, and add it to the current user’s authorized keys.

cd
sshgen -f company
# set it up with no password
cat company.pub >> .ssh/authorized_keys
# make sure to save off the public and private keys.  One way: 
aws s3 cp company s3://my-bucket/company
aws s3 cp company.pub s3://my-bucket/company.pub

Location for sudo privs

/etc/sudoers.d/cloud-init

Also helpful: http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/managing-users.html

Linux Cheat Sheet

One purpose of this blog is to have a convenient place for me and others to look up repeatable processes. In this case, it’s mostly about me. But you are welcome.

Minimal explanation here – There are good explanations of these steps elsewhere on the web. Double click the code boxes to copy (YMMV).

User-related commands

Mount Disk

Situation: You spin up a Linux instance with an additional drive, which you would like to access as /data.

sudo -i  #if necessary
lsblk    #if necessary
mkfs -t ext4 /dev/xvdb
mkdir /data
sudo mount /dev/xvdb /data
cp /etc/fstab /etc/fstab.orig
echo "/dev/xvdb   /data   ext4  defaults,nofail 0 2" >> /etc/fstab 
mount -a   #test

Basic Run Script

If your linux dist uses Upstart, put something like this into /etc/init/myapp.conf.

description "A Bamboo remote agent daemon job file for Upstart"
author "Your name"
start on runlevel [2345]
stop on shutdown
setuid bamboo
setgid bamboo
 
pre-start script
  logger "[`date`] Bamboo remote agent starting"
  exec /etc/init.d/bamboo-agent.sh start
end script
 
pre-stop script
  exec /etc/init.d/bamboo-agent.sh stop
  logger "[`date`] Bamboo remote agent stopping"
end script

Source