How to avoid sudo password only for certain commands
How to shutdown/reboot
How to set ubuntu server to have LAN internet connection
Sudo nano etc/network/interfaces
How to create symlinks inside shared folders on VirtualBox?
How to tell which process is holding onto what port
How to synchronise the server clock
How to track a log file that changes as time goes by
How to set ubuntu server to have LAN internet connection (Static)
Another way to set up static IP
How to change machine name
How to fix errors involving missing erl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
LANGUAGE = (unset),
LC_ALL = (unset),
LANG = "en_US.UTF-8"
are supported and installed on your system.
perl: warning: Falling back to the standard locale ("C").
How to mount flash drive in Ubuntu Server
How to find Installed Packages Location:
All installed packages via apt-get goes into the directory: /var/cache/apt/archives
How to have shared folders on Ubuntu VM via Virtual Box
How to install Guest Additions
Install LibreOffice to Ubuntu
Install unoconv package (works for >= 12.04)
Create New SSH keys
Gain remote access to another server using ssh
have a mail smtp host on ubuntu server
Add www-data to sudoers file
Allow all sudoers to execute sudo without password
Change password for other users
Setup ssh login without password
a) Make .ssh folders for the user b On B
b) Actually assign a’s public key into user b on B as an authorized key
Pdftotext how to convert to and from pdf
Prepare /var/virtual for webapp source code
update packages including those kept back
how to purge old kernel packages when run of disk space
how to display list of users and their ids
how to remove the 12 packages can be installed message when you login via ssh
if ubuntu is guest OS, ssh into it
How to unzip zip file in terminal
How to install Jenkins on ubuntu
How to configure jenkins to use subdomain like ci.example.com
How to make prompt appear if it is missing
This account is currently not available
How to find out full path of a command
How to update known_hosts file when the ip address changes for a server and you try to ssh
How to allow a certain command be sudo by a particular user without password prompted.
how to prepare server for ssh agent forwarding
show all users
How to use tar and gzip
Creating a tape archive:
Listing the contents of an archive:
Extracting all files from an archive:
Compress:
Decompress:
Update system clock
Sync Clock Via NTP
Setup Puppet Master on Ubuntu 12.04 LTS
How to update to higher versions of ubuntu
Verify your settings on ubuntu Check version
How to restart jenkins when you accidentally lock yourself out by security
How to find all files and delete
How to avoid sudo password only for certain
commands
http://askubuntu.com/questions/159007/how-do-i-run-specific-sudo-commands-without-a-passw
ord
sudo visudo
then type something like
jenkins ALL=(root) NOPASSWD: /usr/local/bin/composer.phar
where jenkins is the user alias
How to shutdown/reboot
To shutdown safely:
sudo shutdown -h now
To reboot:
sudo reboot
How to set ubuntu server to have LAN internet
connection
Sudo nano etc/network/interfaces
Add the following lines
auto eth0
iface eth0 inet dhcp
Sudo etc/init.d/networking restart
How to create symlinks inside shared folders on
VirtualBox?
The problem is basically because `yo angular appname` will attempt to create symlinks.
There is an issue with creating symlinks inside SharedFolders for VirtualBox VMs.
The solution is that
a) make sure you are running Linux variant as Host OS (Mac, Linux, etc)
b) Shut down your VM.
c) run the following command in your host OS terminal.
VBoxManage setextradata VMNAME
VBoxInternal2/SharedFoldersEnableSymlinksCreate/SHAREDFOLDERNAME 1
where you need to replace `VMNAME` and `SHAREDFOLDERNAME`
d) now re-run the VM and execute the `yo angular appname`. If need be remove any previously
created files and folders by your previous `yo angular appname` command before re-running it.
http://stackoverflow.com/a/20002108/80353
How to tell which process is holding onto what port
netstat -tulpn
How to synchronise the server clock
timedatectl
You should expect the following:
Local time: Fri 2017-08-04 14:10:43 SGT
Universal time: Fri 2017-08-04 06:10:43 UTC
Timezone: Asia/Singapore (SGT, +0800)
NTP enabled: yes
NTP synchronized: yes
RTC in local TZ: no
DST active: n/a
How to check if pinging to ntp servers?
ntpq -c lpeer
You should see
remote refid st t when poll reach delay offset jitter
=========================================================================
=====
61-216-153-106. .INIT. 16 u - 64 0 0.000 0.000 0.000
61-216-153-105. .INIT. 16 u - 64 0 0.000 0.000 0.000
fwdns2.vbctv.in .INIT. 16 u - 64 0 0.000 0.000 0.000
y.ns.gin.ntt.ne .INIT. 16 u - 64 0 0.000 0.000 0.000
alphyn.canonica .INIT. 16 u - 64 0 0.000 0.000 0.000
To sync, run sudo apt-get install ntp
How to track a log file that changes as time goes by
tail -f /path/to/log
How to set ubuntu server to have LAN internet
connection (Static)
Make sure etho is down.
Command:
sudo ifdown eth0
Go to:
Sudo nano etc/network/interfaces
Add the following lines
auto eth0
iface eth0 inet static
address <ip address>
netmask <subnet mask>
gateway <gateway address>
Then bring interface up:
sudo ifup eth0
If doesn’t work, restart networking service:
/etc/init.d/networking restart
Another way to set up static IP
1. ensure that dhcp is working in interfaces.
2. run sudo ifconfig eth0 150.236.108.17 netmask 255.255.254.0
To go back to dhcp again use
sudo dhclient eth0
https://help.ubuntu.com/10.04/serverguide/network-configuration.html
To configure a default gateway, you can use the route command in the following manner. Modify
the default gateway address to match your network requirements.
sudo route add default gw 10.0.0.1 eth0
To verify your default gateway configuration, you can use the route command in the following
manner.
route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
10.0.0.0 0.0.0.0 255.255.255.0 U 1 0 0 eth0
0.0.0.0 10.0.0.1 0.0.0.0 UG 0 0 0 eth0
How to change machine name
You need to edit the computer name in two files:
/etc/hostname
and
/etc/hosts
These will both need administrative access, so run
gksu gedit /path/to/file
Replace any instances of the existing computer name with your new one. When complete
run
sudo service hostname start
The name will also be changed if you restart your computer.
(p.s the sudo service hostname start didn't work so had to restart the computer)
How to fix errors involving missing erl: warning:
Setting locale failed.
perl: warning: Please check that your locale settings:
LANGUAGE = (unset),
LC_ALL = (unset),
LANG = "en_US.UTF-8"
are supported and installed on your system.
perl: warning: Falling back to the standard locale
("C").
On ubuntu, need to add in the following:
sudo locale-gen en_US en_US.UTF-8
sudo dpkg-reconfigure locales
quit the ubuntu and restart it for the changes to work.
if you need to ssh into the server, on the machine you ssh from make sure that you add the
following to your own .bashrc and .bash_profile
# Setting for the new UTF-8 terminal support in Lion
export LC_CTYPE=en_US.UTF-8
export LC_ALL=en_US.UTF-8
and then RESTART the terminal.
read the following:
http://stackoverflow.com/a/7413863/80353
http://stackoverflow.com/a/5243258/80353
How to mount flash drive in Ubuntu Server
https://help.ubuntu.com/community/Mount/USB
Step 1: Type “sudo fdisk -l” to check which disk the USB is detect on. (e.g. /dev/sdb1)
Step 2: Create a folder where you want the USB to be mounted on (e.g. /media/usb)
Type “sudo mkdir /media/usb”
Step 3: Mount the usb
For FAT type hard disk:
Type “sudo mount -t vfat /dev/sdb1 /media/usb -o
uid=1000,gid=1000,utf8,dmask=027,fmask=137” <- This is based on Step 1 and 2 examples.
For NTFS hard disk:
sudo mount -t ntfs-3g /dev/sdb1 /media/usb
To unmount, type: “sudo umount /dev/sdb1” || “sudo umount /media/usb”
How to find Installed Packages Location:
All installed packages via apt-get goes into the directory: /var/cache/apt/archives
How to have shared folders on Ubuntu VM via Virtual
Box
1. VBox > Settings > Shared Folders and add the folder you want to share inside VM
2. Choose auto mount and permanent if available.
3. check /media inside VM. Does it show /sf_SharedFolderName?
a. if no, install GuestAdditions
b. if yes, you have successfully mounted a shared folder.
How to install Guest Additions
Go here to download http://download.virtualbox.org/virtualbox/
Look for the version and then download the iso
Read this http://docs-v1.vagrantup.com/v1/docs/base_boxes.html
sudo apt-get install linux-headers-$(uname -r) build-essential
sudo apt-get install dkms -y
sudo mount /dev/cdrom /media/cdrom
sudo sh /media/cdrom/VBoxLinuxAdditions.run
sudo apt-get install openssh-server
How to mount your shared folder to another part of
the VM
1. Create the folder that you want the shared folder to appear as well.
Eg:
inside /var/virtual you do a mkdir SharedFolder so that you have a
/var/virtual/SharedFolder
2. Now you need to create a script so that everytime you turn on the vm, you automatically
mound this shared folder to /var/virtual/SharedFolder.
Eg:
sudo nano /etc/init/automountSharedFolder.conf
3. inside the conf file, type the following.
description "this is to mount the /media/sf_SharedFolder into
/var/virtual/SharedFolder"
start on startup
task
exec mount -t vboxsf <SharedFolder> -o rw,dmode=755,gid=33,uid=33
/var/virtual/<SharedFolder>
Please take note that the gid and uid must match the of the owner of the
/var/virtual/<SharedFolder>
Replace <SharedFolder> with the actual name.
4. restart the VM.
5. check /var/virtual/<sharedfolder> you should see the shared folder successfully mounted
there as well.
Check out the answer in http://superuser.com/a/527991/8184
Install LibreOffice to Ubuntu
sudo apt-get install libreoffice-core libreoffice-common libreoffice-writer libreoffice-calc
python-uno
Install unoconv package (works for >= 12.04)
cd /tmp
git clone https://github.com/dagwieers/unoconv
cd unoconv/
## if need be, install make
sudo apt-get install make
sudo make install
cd ../
rm -Rf unoconv/
change the /etc/environment to include
UNO_PATH=/usr/lib/libreoffice
for 14.04
simply do
sudo apt-get install unoconv -y
Create New SSH keys
ssh-keygen -t rsa -C "your_email@youremail.com"# Creates a new ssh key using
the provided email
# Generating public/private rsa key pair.
# Enter file in which to save the key (/Users/you/.ssh/id_rsa): [Press enter]
Gain remote access to another server using ssh
Just like you use a remote control to change channels on a tv without touching a tv, you can
also gain access to a server without actually be in direct contact with a server.
usually you gain access by going to your terminal and type
ssh username@server-ip-address
e.g.,
ssh root@198.61.169.10
or if you have associated the IP Address with a domain, you can do
ssh root@example.com
have a mail smtp host on ubuntu server
install postfix
https://help.ubuntu.com/community/Postfix
Add www-data to sudoers file
What this is: we want to add a particular user account to the list of sudoers
Run the following as root:
sudo adduser www-data sudo
Allow all sudoers to execute sudo without password
Your main user is member of group 'sudo'. Default settings is to ask your password in order to
perform any activity which requires some privilegies.
in order to change it, you need to run in a terminal:
sudo visudo
and change this line:
%sudo ALL=(ALL:ALL) ALL
for this line:
%sudo ALL=(ALL:ALL) NOPASSWD: ALL
save the changes and close your session to have your system taking the changes.
Change password for other users
Run the following as root:
passwd www-data
Setup ssh login without password
Assume you want to login from a@A to b@B
First we assume that you have already created your private/public key pair
a) Make .ssh folders for the user b On B
Now use ssh to create a directory ~/.ssh as user b on B. (The directory may already exist,
which is fine):
a@A:~> ssh b@B mkdir -p .ssh
b@B's password:
Warning!! Sometimes, you get a host key verification failed message. This means
that probably you change the IP address of the server. Reset your known_hosts
file like this.
Note: for ssh via a different port number like 3022, use
ssh -p 3022 b@B mkdir .ssh
b) Actually assign a’s public key into user b on B as an authorized key
Finally append a's new public key to b@B:.ssh/authorized_keys and enter b's password one
last time:
a@A:~> cat ~/.ssh/id_rsa.pub | ssh b@B 'cat >> .ssh/authorized_keys'
b@B's password:
Note: for ssh via a different port number like 3022, use
cat ~/.ssh/id_rsa.pub | ssh -p 3022 b@B 'cat >> .ssh/authorized_keys'
From now on you can log into B as b from A as a without password:
a@A:~> ssh b@B hostname
B
A note from one of our readers: Depending on your version of SSH you might also have to
do the following changes:
● Put the public key in .ssh/authorized_keys2
● Change the permissions of .ssh to 700
● Change the permissions of .ssh/authorized_keys2 to 640
Pdftotext how to convert to and from pdf
sudo apt-get install poppler-utils
Prepare /var/virtual for webapp source code
Create the following folders if you want to have 1 production instance and 1 stage instance for
the same webapp
login as www-data
navigate to /var/virtual
use mkdir to create the following folders like:
webapp.com
stage.webapp.com
The permissions of the folders should be 775
Or you can use
bash -c "$(curl -fsSL https://raw.github.com/gist/4528222)" <webapp.com>
this is the script https://gist.github.com/4528222
update packages including those kept back
sudo apt-get update -y
sudo apt-get dist-upgrade -y
will update all packages including those kept back.
After this, run
sudo apt-get autoremove -y
This will remove any unwanted packages.
You will be prompted to restart the system with
Graph this data and manage this system at https://landscape.canonical.com/
*** System restart required ***
Go to your Amazon EC2 or Rackspace to reboot the system.
how to purge old kernel packages when run of disk
space
sudo apt-get autoremove -f
This will forcibly remove unwanted kernel packages
If this doesn't work,
uname -a
to find out current kernel used
then
cd /boot
sudo rm *-3.03-61-generic
and remove any generic that is NOT current kernel.
Then try autoremove again.
Finally
sudo update-grub
how to display list of users and their ids
sudo nano /etc/passwd
how to remove the 12 packages can be installed
message when you login via ssh
this message is called motd or Message of the Day.
There are 2 reasons for this.
1) you have not updated packages that are held back. You need to update all packages
including those held back
2) There is a bug with the motd.tail file. You need to run
sudo touch /etc/motd.tail
if ubuntu is guest OS, ssh into it
http://superuser.com/a/527462/8184
Add a port forwarding rule assuming you are using virtualbox
The best way to login to a guest Linux VirtualBox VM is port forwarding. By default you should
have one interface already which is using NAT. Then go to the Network settings and click the
Port Forwarding button. Add new Rule:
Host port 3022, guest port 22, name ssh, other left blank.
How to unzip zip file in terminal
1. install unzip http://askubuntu.com/a/86852/10591
2. unzip file.zip -d destination_folder
How to install Jenkins on ubuntu
This is greatly referenced from
https://wiki.jenkins-ci.org/display/JENKINS/Installing+Jenkins+on+Ubuntu
Run the following as root:
wget -q -O - http://pkg.jenkins-ci.org/debian/jenkins-ci.org.key | sudo apt-key add -
sh -c 'echo deb http://pkg.jenkins-ci.org/debian binary/ >
/etc/apt/sources.list.d/jenkins.list'
apt-get update -y
apt-get install jenkins -y
adduser jenkins sudo
curl -L http://updates.jenkins-ci.org/update-center.json | sed '1d;$d' | curl -X POST -H 'Accept:
application/json' -d @- http://localhost:8080/updateCenter/byId/default/postBack
or you can use
bash -c "$(curl -fsSL
https://gist.githubusercontent.com/simkimsia/4473000/raw/6adbd05cc3b8aaa5fb9cf1d7d4a5a0eaef273
21a/install-jenkins-on-ubuntu-12-10.sh)"
The script is here https://gist.github.com/4473000
It is important all of the above commands are executed. The first is to install. The second adds
`jenkins` to sudoers. The last one is to update the updatecenter so that you can properly use
shortname to install plugins.
if you get a curl: (7) couldn't connect to host
run the curl command again
How to configure jenkins to use subdomain like
ci.example.com
See this https://gist.github.com/simkimsia/5307691
How to make prompt appear if it is missing
Refer http://askubuntu.com/a/232663/10591 for more details
first at root i did a
echo $SHELL
I saw that I have /bin/bash
then i switch to www-data
sudo su www-data
then i do a
echo $SHELL
I saw that I had
/bin/sh
instead.
So I did a
chsh -s /bin/bash
I was prompted for my www-data password so I gave it.
Password:
after that I switch back to root
exit
then i log back into www-data
sudo su www-data
I checked the $SHELL again
echo $SHELL
I saw that now it is
/bin/bash
and also my prompt is back
This account is currently not available
sudo chsh -s /bin/bash username
to change the bash
How to find out full path of a command
If i want to know the full path to `service` as in `sudo service php5-fpm restart`
i will use `which service`
this will return me the full path which is usually \user\sbin\service
How to update known_hosts file when the ip address
changes for a server and you try to ssh
When you try to ssh to a server, sometimes the ip address changes and you get prompted for a
host key verification failed message.
So what you do is you need to reset the known_hosts
ssh-keygen -R hostname
How to allow a certain command be sudo by a
particular user without password prompted.
taken from http://unix.stackexchange.com/a/59843
visudo as root
then
type
Phing ALL=(root) NOPASSWD: /full/path/to/service
assuming Phing is the user.
use which service to find out which service is used
when you change visudo, you need to reboot
how to prepare server for ssh agent forwarding
because sometimes a user needs to mkdir in another dir owned by another user and you do not
wish to change user privileges nor ownership or even which group the user belongs to.
easiest way is to use ssh agent forwarding.
but you need to update the known_hosts file.
otherwise you will keep triggering host key verification error..
so eg jenkins wants to mkdir a folder inside /var/virtual which belongs to www-data
first update the known_hosts inside jenkins
Login as jenkins
Do a
www-data@ipaddress
you will see a
The authenticity of host 'ipaddress (ipaddress)' can't be established.
ECDSA key fingerprint is 95:a3:86:8f:a1:d1:2d:4b:e2:bf:97:e2:92:a1:cd:1d.
Are you sure you want to continue connecting (yes/no)? yes
then allow jenkins to access www-data@ipaddress without prompting for password
show all users
cut -d: -f1 /etc/passwd
How to use tar and gzip
Creating a tape archive:
tar -cf archive.tar myDirectories/
Note - using the "v" flag prints out extra messages, as verbose mode, though it's not related to
extracting files.
Listing the contents of an archive:
tar -tf archive.tar
It is generally a good idea to preview the contents of tape archives before unpacking them. This can
become a serious problem if you are currently root, and the archive just happens to jump out of the
current directory, and write over some important system files.
Extracting all files from an archive:
tar -xf archive.tar
To extract just partial pieces from the archive, supply a file or directory name after the archive name.
You can list as many as desiered here, separated by spaces.
tar -xf archive.tar filename
Compress:
gzip archive.tar
Decompress:
gunzip archive.tar.gz
Merging files
The "z" flag works with gzip, to either create a tar/gzipped archive:
tar -czvf archive.tgz files/
...or decompress a tar/gzipped archive:
tar -xzvf archive.tgz
Update system clock
Sync Clock Via NTP
If you want to sync your clock with NTP servers, it is also very easy. Just make sure you have the file ntp.conf file in
/etc. How can you check it?
ls /etc/ntp.conf
If you see /etc/ntp.conf as a result, you already have that file. If the ls command gives an error, you do not have it. If
so, you may create it yourself.
sudo vim /etc/ntp.conf
This file will be used to automatic synchronization of the clock. I do not know if the client uses this file automatically or
one has to configure something first. Thanks to Sean (see comment below): You need to install ntpd in order to make
use of this ntp.conf file.
Whether you have the file already or not, make sure it has at least the following data
driftfile /var/lib/ntp/ntp.drift
server 0.pool.ntp.org
server 1.pool.ntp.org
server 2.pool.ntp.org
server pool.ntp.org
Here you may replace, add, and/or remove any servers you wish. You will find a list of time servers from the public
NTP time server list.
You may manually sync the clock using the following
sudo ntpdate servername
where servername can be any public or private time server. You may always choose the following without hesitation
sudo ntpdate pool.ntp.org
If you don’t have ntpdate installed, you can install it via:
sudo aptitude install ntpdate
Setup Puppet Master on Ubuntu 12.04 LTS
1. http://docs.puppetlabs.com/guides/puppetlabs_package_repositories.html#for-debian-an
d-ubuntu
2. wget https://apt.puppetlabs.com/puppetlabs-release-precise.deb
sudo dpkg -i puppetlabs-release-precise.deb
sudo apt-get update
3. if the server is hosted somewhere in internet, use
sudo vim /etc/hosts
and add puppet to the 127.0.0.1 entry
4. install the Jenkins see How to install Jenkins on ubuntu
5. switch to Cloudflare for your domain
6. wait for 24 hours before the nameservers DNS switches over to cloudflare
How to update to higher versions of ubuntu
$ sudo apt-get update
$ sudo apt-get install update-manager-core
then
$ sudo do-release-upgrade
if still no release
do
sudo do-release-upgrade -d
taken from
http://www.cyberciti.biz/faq/howto-upgrade-to-ubuntu-14-04-from-ubuntu-13-10-or-12-04/
A better answer is here for silent upgrade using defaults:
http://askubuntu.com/a/304980/10591
Verify your settings on ubuntu Check version
$ lsb_release -a
$ uname -mrs
$ tail -f /var/log/app/log/file
How to restart jenkins when you accidentally lock
yourself out by security
root access and then navigate to /var/lib/jenkins
vim config.xml
look for useSecurity and change true to false
sudo reboot to restart server
worst case scenario is
sudo apt-get remove jenkins
then reinstall
How to find all files and delete
find . -name "*.txt" -type f -delete