I am trying to understand this docker file
FROM ubuntu:trusty
MAINTAINER Wurstmeister
RUN apt-get update; apt-get install -y unzip openjdk-7-jre-headless wget supervisor docker.io openssh-server
ENV JAVA_HOME /usr/lib/jvm/java-7-openjdk-amd64/
RUN echo 'root:wurstmeister' | chpasswd
RUN mkdir /var/run/sshd
RUN sed -i 's/PermitRootLogin without-password/PermitRootLogin yes/' /etc/ssh/sshd_config
EXPOSE 22
I understood most of the lines but I don't understand what these below lines means?
apt-get install -y unzip openjdk-7-jre-headless wget supervisor docker.io openssh-server
echo 'root:wurstmeister' | chpasswd
sed -i 's/PermitRootLogin without-password/PermitRootLogin yes/' /etc/ssh/sshd_config
Can anyone help me understand? I am not sure what is the purpose of wget supervisor docker.io openssh-server in that line. Also what does echo mean there? And then also last sed line.
apt-get install -y unzip openjdk-7-jre-headless wget supervisor docker.io openssh-server
Installs a bunch of packages using the ubuntu package manager (the base image is Ubuntu Trusty 14.04).
The -y option is used to prevent apt from asking user confirmation about installing the packages and their dependencies: the installation just proceeds without need for any input. This is needed to avoid hanging the process of building the docker image. Packages installed:
openssh-server: so that the container can act as an ssh server and process requests from ssh clients
wget, unzip: utilities
java: eventually this container is used to allow users to access it via ssh, maybe those users need java
supervisor, docker.io: I don't see a direct usage of it in the Dockerfile itself
then
echo 'root:wurstmeister' | chpasswd
Changes password of user root to wurstmeister
sed -i 's/PermitRootLogin without-password/PermitRootLogin yes/' /etc/ssh/sshd_config
Replaces the text PermitRootLogin without-password with PermitRootLogin yes in file /etc/ssh/sshd_config to allow root user to login with password or without (e.g., with public key).
An important general note: If you run SSHD in your Docker containers, you're doing it wrong!
wget supervisor docker.io openssh-server are parameters to the apt-get call. Those are the names of the packages to be installed.
echo is used in combination with | to send the new password to the chpasswd command.
sed is used to update some text in a configuration file (here to allow passwordless login). The s/text/newText/ part does text substitution.
Related
Hello is this possible to create a file with these line of codes below and make it as an executable file on single line of code? Currently I'm doing manually. Your response is highly appreciated. Thank you
Manual Steps
-vi + content
-chmod +x filename
This is the file content:
#!/bin/bash
sudo apt-get update
sudo apt install curl -y
sudo apt install -y default-jdk
Screenshot:
CLI Image
Objective to write everything using one line of code
If it is crucial that it be a one-liner and vi is not a requirement:
echo -e '#!/bin/bash\nsudo apt-get update\nsudo apt install curl -y\nsudo apt install -y default-jdk' > test.sh && chmod +x test.sh && ./test.sh
If vi is a requirement you could do something like:
vim file.txt "+i#!/bin/bash" "+osudo apt-get update" "+o..." and so on
in place of the echo, but this seems much less effective to me and I'm less familiar with using vi in this way.
You could generate a test.sh with bash script (we can call it download.sh):
# 1. write script content to test.sh
cat <<EOT >> test.sh
#!/bin/bash
sudo apt-get update
sudo apt install curl -y
sudo apt install -y default-jdk
EOT
# 2. make it executable
chmod +x test.sh
When you execute bash download.sh, it will generate a test.sh automatically.
I've been attempting to write a shell script to detect composer and git on a virtual linux = Ubuntu 16.0.4 machine and then install them if needed. + clone the required repository if the machine is ready for it.
Now this is my first attempt to write any kind of script and also sorry if somehow I messed up the question itself, I'm quite now on stackoverflow as well.
Any help is appreciated, thanks in advance.
Here's the original task specification I received initially:
-check if git is installed on server
if so, clone repo with codebase
-check if composer is installed on server
if so, composer install in the root directory of the laravel application
-finally, php artisan migrate --seed
Now this is how I was trying to achieve this:
#!/bin/bash
echo "The installation process is about the begin..."
if ! which git;
then echo "Git has been located on the destination system. Cloning begins..."
git clone <link to the gitlabe repo>
else echo "There is no Git installed on the system. Git installation commences..."
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install git
echo "Cloning begins..."
git clone <link to the gitlabe repo>
fi
if ! which composer;
then
echo "Composer has been located on the destination system."
else
echo "There is no Composer installed on the system. Composer installation commences..."
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install composer
fi
sudo apt-get update
sudo apt-get install curl php5-cli git
curl -sS https://getcomposer.org/installer | sudo php -- --install- dir=/usr/local/bin --filename=composer
composer global require "laravel/installer"
sudo apt-get update
'Now the preferred version in the vagrantfile has to be edited to be 1.8.1 instead of 1.9'
'Generate a ssh key'
ssh-keygen -t rsa -b 4096 -C "< e-mail adress that I used >"
'Start ssh agent eval $'
ssh-agent -s
'Add your SSH private key to the ssh-agent'
ssh-add -K ~/.ssh/id_rsa
php artisan migrate --seed
The error message I recieve:
sudo sh ./testscript.sh
[sudo] password for linuxtest:
The installation process is about the begin...
: not foundt.sh: 3: ./testscript.sh:
: not foundt.sh: 4: ./testscript.sh:
: not foundt.sh: 5: ./testscript.sh:
./testscript.sh: 72: ./testscript.sh: Syntax error: end of file unexpected (expecting "then")
The answer that helped me solve my problem was posted by Charles Duffy in a comment:
This looks like your file has DOS rather than UNIX newlines. This will prevent syntax like fi from being recognized, because it's read as fi$'\r', which isn't a keyword.
#!/bin/bash
echo "The installation process is about the begin...";
if [ -x "$(command -v git)" ]; then
echo "Git has been located on the destination system. Cloning; begins..."
git clone <link to the gitlabe repo>;
else
echo "There is no Git installed on the system. Git installation commences...";
sudo apt-get update && sudo apt-get upgrade && sudo apt-get install git;
echo "Cloning begins...";
git clone <link to the gitlabe repo>;
fi
if [ -x "$(command -v composer)" ]; then
echo "Composer has been located on the destination system.";
else
echo "There is no Composer installed on the system. Composer installation commences...";
sudo apt-get update && sudo apt-get upgrade && sudo apt-get install composer;
fi
Hey there
I think this should fix your If condition problem. If you want to know more about how you should check for the case that a programm exists, look here:
Check if a program exists from a Bash script
Its the second answer for a quickfix.
Always remember to chain commands which are depending on the success of the preceding command via "&&". This secures that the next command will just be executed if the preceding doesn't fail.
I recommend doing it the same way with the ssh commands.
#edit
also make sure that you end each command with a semicolon.
hope I could help.
So, I have to setup several server that requires mysql-server on each and every one of them. I decided to write a shell script to enter a input to whiptail which require the user to input password. I wrote the bash script but it just does not response when it reach the whiptail page, can anyone help me with this? Thanks
#!/bin/bash
sudo apt-get install mysql-server <<< "yes
mypassword
"
First when the sudo apt-get ask about whether to install or not it supplies yes, but then when it came to whiptail it does not provide any input as it should be which is mypassword
Rather than providing input to whiptail, you can run apt-get install like this to skip prompts during installation:
DEBIAN_FRONTEND="noninteractive" apt-get install -y mysql-server
If you want to provide a root password as well, you can do this:
export DEBIAN_FRONTEND="noninteractive"
sudo debconf-set-selections <<< "mysql-server mysql-server/root_password password myrootpw"
sudo debconf-set-selections <<< "mysql-server mysql-server/root_password_again password myrootpw"
sudo apt-get install -y mysql-server
Take care to not accidentally expose your root password (i.e. ensure it doesn't end up in your history, securely delete any script files containing it, I'm sure there are others).
I found this information here.
I have a vagrant box up running hashicorps' precise 64 (which is ubuntu I believe). I am installing kong. I have installed kong but now need to install cassandra since kong uses that as a data center. I am following this guide:
http://cassandra.apache.org/download/
I couldn't find the cassandra.sources.list file inside the /etc/apt/sources.list.d/ directory so I created that file and inserted the following:
echo "deb http://www.apache.org/dist/cassandra/debian 22x main" | sudo tee -a /etc/apt/sources.list.d/cassandra.sources.list
but when I update the repository by sudo apt-get update, I get the following error: Type 'echo' is not known on line 1 in source list /etc/apt/sources.list.d/cassandra.sources.list
Any ideas? Im compeltely new to debian and linux based OS's.
You dont have to copy the line in your file, it is a command that you execute. so directly execute the command from your bash system and it will update the right file for you
$ echo "deb http://www.apache.org/dist/cassandra/debian 22x main" | sudo tee -a /etc/apt/sources.list.d/cassandra.sources.list
If you really want to create and update the /etc/apt/sources.list.d/cassandra.sources.list file, you just need to add the line as
deb http://www.apache.org/dist/cassandra/debian 22x main
After this you can safely run the update to install cassandra
$ sudo apt-get update
$ sudo apt-get install cassandra
After following this tutroial I get the following error when trying to run the commands as user or even sudo:
sudo: no tty present and no askpass program specified
The comments from Lurdan in this article state that you need to run
sudo -S <YOUR_COMMAND>
chmod 0666 /dev/tty
chmod doesn't work but sudo -S does, but surely there's another fix?
So silly, after looking further down I see a solution from Beorat:
To avoid the sudo tty issue and others, run these commands just before running do-release-upgrade:
sudo -S apt-mark hold sudo
sudo -S apt-mark hold procps
sudo -S apt-mark hold strace
If you've already upgraded, run the above commands, then manually downgrade to the Trusty packages:
sudo -S wget http://mirrors.kernel.org/ubuntu/pool/main/s/sudo/sudo_1.8.9p5-1ubuntu1.1_amd64.deb
sudo -S wget http://mirrors.kernel.org/ubuntu/pool/main/p/procps/procps_3.3.9-1ubuntu2_amd64.deb
sudo -S wget http://mirrors.kernel.org/ubuntu/pool/main/s/strace/strace_4.8-1ubuntu5_amd64.deb
sudo -S dpkg -i sudo_1.8.9p5-1ubuntu1.1_amd64.deb
sudo -S dpkg -i procps_3.3.9-1ubuntu2_amd64.deb
sudo -S dpkg -i strace_4.8-1ubuntu5_amd64.deb
More info here: https://github.com/Microsoft/BashOnWindows/issues/482
WSL uses the lxrun executable for management from Windows:
lxrun -h
Usage:
/install - Installs the subsystem
Optional arguments:
/y - Do not prompt user to accept
/uninstall - Uninstalls the subsystem
Optional arguments:
/full - Perform a full uninstall
/y - Do not prompt user to accept
/setdefaultuser - Configures the subsystem user that bash will be launched as. If the user does not exist it will be created.
Optional arguments:
username - Supply the username
/y - If username is supplied, do not prompt to create a password
/update - Updates the subsystem's package index
Given that, you can use lxrun /setdefaultuser root. Just thought I'd point out this side of it since it was required when I ran into the same issue as you after trying to upgrade to Xenial. I can confirm that running this command, then the wget / dpkg commands my issues were resolved.
The commands I used:
wget http://mirrors.kernel.org/ubuntu/pool/main/s/sudo/sudo_1.8.9p5-1ubuntu1.4_amd64.deb
wget http://mirrors.kernel.org/ubuntu/pool/main/p/procps/procps_3.3.9-1ubuntu2_amd64.deb
wget http://mirrors.kernel.org/ubuntu/pool/main/s/strace/strace_4.8-1ubuntu5_amd64.deb
dpkg -i sudo_1.8.9p5-1ubuntu1.4_amd64.deb
dpkg -i procps_3.3.9-1ubuntu2_amd64.deb
dpkg -i strace_4.8-1ubuntu5_amd64.deb
Finally, you might need to run sudo apt-get install -f in case you get The following packages have unmet dependencies [xxx] but it is not going to be installed
I got rid of the error by moving /etc/hosts to /etc/hosts.bu. After closing the shell en opening again, /etc/hosts is recreated and your computer name is added. The error is gone (for me.)