Training Handout¶
1. Introduction to ScienceCloud¶
2. Hands-on Part¶
2.1. Sign up for ScienceCloud¶
-
Get in touch with Science IT.
-
Your account has been activated?
-
Open a web browser and go to https://cloud.s3it.uzh.ch (javascript and cookies must be enabled).
-
Log in with your UZH webpass (the usual shortname and password).
-
Note
If you have signed up for the ScienceCloud Base training but are not part of any other ScienceCloud tenants yet, the credentials will not work because your account is not yet active. At the beginning of the training session, you will be added to the training project thus activating the account.
2.2. Get access to your instances¶
An SSH key is required to log into your newly created instances: SSH keys have several advantages over regular username/password authentication, but the main reason we use those is that they are really difficult to crack with a brute force approach. SSH keys are made up of two components system: a private key and a public key. The public key resides on the computer/instance you would like to connect to. The private key stays on your own computer. A SSH connection can only be established between a computer having the private key and a computer/instance having the corresponding public key. It's therefore important to never share your private key file.
Create a key on Linux/Mac/Windows10¶
ssh-keygen -t rsa -b 4096
The above command will prompt you to set a password to unlock the key. If you accept the default options offered by ssh-keygen it subsequently generates two files named id_rsa.pub and id_rsa and saves them under /home/<user>/.ssh/
Note
Ubuntu 16.04 does not support DSA cipher suite for generating the key pair.
Note
If invoking ssh
from the Windows10 terminal leads to an error please refer to this quick guide or to Microsoft documentation or install an external application providing a ssh client and a key generator (see "Create a keypair on older Windows")
These files can be confirmed / displayed using
ls .ssh
which should show something similar to id_rsa id_rsa.pub known_hosts
.
To display the content of the id_rsa.pub file, which is the public half of your key, you can issue:
cat ~/.ssh/id_rsa.pub
which displays something like
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC6D3RuR2j6BvVy6I3Q1amScKYFs+qmI5D37bS9/vgdUvbQx0CnkyuAsx7UpPltXTz3+jkIcGJQqZJUZV1v00/y4iiaHTzp/PxRMT8bzIMw9cOnfZxhSQ1ekUr+wTfT8e5Hs+NabP4bfni/htE7LBk+Mrywgb5I4Mr3fKmKGH4DJzh2YUCt6oC/TivxuKYVrQPEy0BznFuwrHbpQoT6swUa3GaB5nIi/nPyHd6E/EIZ1be+U2y7+efmY9JlQKLaJg6iYumSbibLBQ8qw+ohHbcSBhDUmEiOosuYtvv8L8r3Bvj+2zyFU5DdArSvIPFQbma3/s9oqfYctcqGzVRmFeeJ
Once the generation process is complete there are a few extra steps that needs to be followed:
- Log in to https://cloud.s3it.uzh.ch, choose Access & Security.
- Go to Keypairs tab, which shows the key pairs that are available for this project.
- Select Import Keypair and choose the Keypair Name.
- Paste the content of your SSH public key in the Public Key text section
Create a keypair on older Windows¶
Latest/updated versions of windows have the ssh client already available in the command line. If the above commands do not work, you can try to install the relevant update to enable ssh in the command prompt or use a third party application.
The first option can be achieved following the info on this quick guide or to Microsoft documentation , while the following steps need to be followed in order to use the third party application "PuTTY":
- Download PuTTYgen from this link.
- Open the PuTTYgen program.
- For Type of key to generate, select SSH-2 RSA.
- Click the Generate button.
- Move your mouse in the area below the progress bar. When the progress bar is full, PuTTYgen generates your key pair.
- Type a passphrase in the Key passphrase field. Type the same passphrase in the Confirm passphrase field. You can use a key without a passphrase, but this is not recommended.
- Click the Save private key button to save the private key. ⚠️ You must save the private key.
- Right-click in the text field labeled Public key for pasting into OpenSSH authorized_keys file and choose Select All and Copy.
- Then:
- Log in to https://cloud.s3it.uzh.ch, choose Access & Security.
- Keypairs tab, which shows the key pairs that are available for this project.
- Import Keypair.
- Choose the Keypair Name.
- Paste in the Public Key text section the content of your ssh public key.
2.3. Launch an instance¶
- Log in to https://cloud.s3it.uzh.ch.
-
On the Project tab, open the Compute tab and click Images category.
-
The dashboard shows three different sets of Images available: Project, Shared With Me, Public.
-
For the scope of the training, go to Public and look for the latest Ubuntu. You can spot it as the name starts with '***', has the higher distribution version and the latest build date: i.e. " ***Ubuntu 22.04 (2024-05-29) ". A complete list of the supported public images can be found at: Supported Images.
-
Click Launch Instance.
-
In the Launch Instance dialog box, specify the following values:
- Instance Name: Assign a name to the virtual machine.
- Instance Count: To launch multiple instances, enter a value greater than 1. (The default is 1.)
- Flavor: Specify the size of the instance to launch. Check the user guide paragraph on flavors for detailed information.
- Networks: To add a network to the instance, click the "+" of uzh-only Network field.
- Key Pair: Check that your key pair is added to the instance.
Congratulation you've just launched your first instance on ScienceCloud!
Tip
If your instance does not launch correctly and ends up in an "error" status, you might want to check if the flavor is available on the ScienceCloud flavor availability report (requires internal network or VPN). If the flavor is not available, delete the error vm and try with an available flavor, otherwise contact us.
2.4. Login to your instance¶
On Linux/Mac/Windows10 run SSH in terminal¶
The long way:
ssh -i ~/.ssh/id_rsa ubuntu@<your-instance-ip-address>
One way to simplify ssh connections that are often used is to add the key to the ssh-agent.
To avoid inserting the passphrase of the private key each time you open a new connection, run:
ssh-add <path-to-id_rsa>
ssh ubuntu@<your-instance-ip-address>
Note
Regarding usernames The convention used for usernames used by the public images on ScienceCloud is straightforward: each distribution has a predefined user with the same name. I.e., every flavor of Ubuntu has username "ubuntu", Debian distros have "debian", CentOS have "centos" and so on. See here for information on what user to use with each image.
On older Windows¶
- Get the putty.exe from here and run it.
- Host Name: username@<instance-IP-address> (The username will be
ubuntu
if you've chosen Ubuntu for your instance) - Connection type: select SSH.
-
In the Category pane, expand Connection, expand SSH, and then select Auth.
-
Click Browse.
-
Select your private key
.ppk
file that you generated for your key pair, and then click Open.
-
-
(Optional) If you plan to start this session again later, you can save the session information for future use. Select Session in the Category tree, enter a name for the session in Saved Sessions, and then click Save.
-
Pressing the ‘Open’ button PuTTY will begin trying to connect you to the instance.
- If this is the first time you connect to the instance, PuTTY displays a security alert box, click "Yes" to confirm you trust the host.
2.5. Install packages on a Debian/Ubuntu instance¶
Steps to install a new software package or upgrade existing software packages on a Debian/Ubuntu system.
- To update the list of packages known by your system, you can run:
sudo apt-get update
- To upgrade all the packages on your system (without installing extra packages or removing packages), run:
sudo apt-get upgrade
Hint
The upgrade process will eventually stop requiring some input, for example asking if keeping or replacing a configuration file changed locally on the machine. In this case the right choice would be to keep the locally modified file, which is the default. In general is correct and safe to always choose the default option when prompted. This behavior can be obtained adding the "-y" option to the upgrade command.
- To install a package and all its dependencies on Ubuntu,
# If you are not sure about the package name or version, try to run a quick search on your repository by:
apt-cache search package_name
# Then install e.g. r-base by:
sudo apt-get install r-base
- To remove the package from your system, run:
sudo apt-get remove r-base
2.6. Attach a volume to the Instance¶
Create a volume¶
- Log in to https://cloud.s3it.uzh.ch.
- On the Project tab, open the Compute tab and click Volumes category.
- Volumes tab.
- Click Create Volume.
- Specify Volume name and Volume Size.
- Press Create Volume.
Attach Volume¶
- On Volumes tab, select your volume.
- From drop-down Edit volume list, select Manage attachments.
-
From Attach to instance list, choose the instance you wish to attach the volume to.
-
Press Attach Volume.
Format and mount the volume¶
Once a volume is attached to a VM it becomes visible to the operating system but it is in a blank state. To make use of it, you need to identify and format it. Follow these steps to do so:
Danger
⚠️ The format operation (step 2) should be performed only once when the volume is attached for the first time. Otherwise, the volume's data will be completely wiped!
- Get the name of the block device your volume is associated to: select the Volume tab on the ScienceCloud GUI and look for entries like
/dev/vd<LETTER>
or/dev/sd<LETTER>
under the Attached To field – where<LETTER>
is a lowercase latin letter likea
,b
, etc. You can also look into the list of all block devices attached to the instance by running the following command:lsblk
- Format your new disk into ext4 (recommended FS). See the "Danger" note above before running this command, and change the device name accordingly.
sudo mkfs.ext4 /dev/vd<LETTER>
- Mount it on your file system
sudo mount /dev/vd<LETTER> /mnt
- Check if it is mounted correctly (there should be a line starting with
/dev/sd<LETTER>
or/dev/vd<LETTER>
)df -h
- Set the ownership of mounted volume to allow ubuntu user for read/write
sudo chown -R ubuntu:ubuntu /mnt
2.7. Copy data to your instance (and back)¶
On Linux/Mac/Windows10¶
Open a terminal on your machine and use scp
.
Note
For both upload and download you have to use scp on your local machine.
Upload:
# Copy the file "foo.txt" from the localhost current directory to the /home/ubuntu/data directory (must exist)
scp foo.txt ubuntu@<your-instance-ip-address>:data/
Download:
# Copy the file "foo.txt" from the instance /home/ubuntu/data directory to the localhost current directory
scp ubuntu@<your-instance-ip-address>:data/foo.txt ./
Tip
You might need to add the "-i PATH_TO_YOUR_PRIVATE_KEY" option if you have your key saved in a non-standard location and you have not added it yet with "ssh-add".
Using Filezilla software¶
- Download Filezilla from here and install it.
- From File menu select Site Manager. You can also press Ctrl+S or Command+S.
- On right panel, select New Site.
- On left panel specify the Host: instance IP address.
- Port: Only if it differs from the standards.
- Protocol: Select SFTP.
- Logon Type: choose Key file.
- User: The user ID to use when connecting (e.g., ubuntu).
- Key file: Browse and select your private key file.
- Login using Connect button.
- Verify the host key fingerprints.
- Drag & drop files from your pc to the instance.
Note
If your private key is in .pem format, a new message will pop up to convert your key into .ppk which is supported by Filezilla.
Warning
⚠️ Due to reported cases of malware being bundled with FileZilla software installers, only use the link above for downloading and installing FileZilla. Specifically: do not install FileZilla from an installer that contains the word "bundle" in its name.
2.8. Snapshot¶
Snapshots are a feature that allows users to capture the running instance setup and save it without the need to pause or shutdown it. These snapshots are disk-only snapshots.
Create a snapshot¶
- Log in to https://cloud.s3it.uzh.ch.
- On the Project tab, open the Compute tab and click Instances category.
- Select the instance you want to take a snapshot of
- recommended: shut off the instance if possible (via the dropdown action menu)
- Click on Create Snapshot
- Snapshot Name: Give the name to your snapshot
- Press Create Snapshot
- New snapshot is displayed in the Images category
Fit-for-a-purpose-snapshots/images: If you would like to have several pre-configured snapshots or images (i.e. VMs ready for a certain purpose), we encourage you to briefly contact us. We frequently have/had similar cases and may be able to simplify your task.
2.9. Protect your instance¶
You can prevent accidental instance(s) deletion by "locking" your instance. The relevant option can be found in the dropdown menu right next to your instance name in the Instances page.
Note
If you lock an instance no actions are possible on it. The error messages you will receive when trying are really generic so do remember which instance you lock or try to unlock them from that same menu in case you notice some inexplicable behaviour.
2.10 Access specific ports on your VM¶
By default the only incoming connections allowed to your VM are via SSH. If you need to access different ports or services running on your VM like a webserver (i.e. open ports 80 and possibly 443) you need to follow these steps:
Create security group¶
- Log in to https://cloud.s3it.uzh.ch
- On the Project tab, open the Compute tab and click Access & Security category.
- Security Groups tab.
- Click Create Security Group.
- Choose the Security Group Name, hit Create.
- Select Manage rules of your group.
- Add rule.
- Enter for example port 80 (http)
Apply new security group to a running virtual machine¶
- Log in to https://cloud.s3it.uzh.ch
- On the Instances tab, open the drop down menu next to your virtual machine and select Edit Security Group
- Enable the newly created security group by clicking on the + sign next to the security group name
Note
There is no reason to remove the default security group from your instance but if you decide to do so make sure you have all the rules you need in the newly created one.
3.0. Further topics¶
You can refer to the ScienceCloud User Guide for the further topics such as Associating the floating IP.
To get additional support to ScienceCloud, you can contact Science IT.