# useful server basics PUBS 2018 | Jean Costello ## log in/out To log in: - $ ssh username@servername.domainname.edu Enter your password when prompted. To log out (use any): - $ logout - $ exit - $ ctrl+D ## create an alias To avoid having to type out the full server name and domain every time, create an alias. 1. open the file ~/.ssh/config 2. add the following three lines to the file: - Host *nickname* - HostName *domain* - User *username* 3. save and exit 4. login by typing: ssh *nickname* An example in vim: 1. $ vim ~/.ssh/config 2. type "i" to inter insert mode 3. enter the text (example): - Host pubs - HostName derisilab105.ucsf.edu - User my_pubs_group 4. type esc to exit insert mode 5. type ":wq" to save and quit (if the program says you may not edit the file, use ! to override: :wq!) 6. $ ssh pubs ## transfer files To move files between your local machine and the server, use the scp (securely copy files) command. **local to remote** - $ scp username@server:file.txt /local/directory/ Or, if you've set up an alias: - $ scp nickname:file.txt /local/directory/ **remote to local** - $ scp file.txt username@server:/remote/directory/ - $ scp file.txt nickname:/remote/directory/ **directories** To transfer directories, use the option r: - $ scp -r /local/directory/ nickname:/remote/directory/ - $ scp -r nickname:/remote/directory/ /local/directory/ ## files List files and file sizes: - $ ls -lh List the number of lines in a file: - $ wc -l file.txt Display the first n lines in a file: - $ head -n file.text Display the last n lines in a file: - $ tail -n file.txt Zip a file: - $ gzip file.txt Unzip a file: - $ gunzip file.txt.gz ## continue processes after logout prefix your command with nohup: - $ nohup command arguments Example: - $ nohup python myscript.py This allows you to logout or disconnect from the server or exit the shell without aborting the command. To save the output to a file: - $ nohup python myscript.py > file.txt ## return to shell prompt immediately suffix your command with & - $ nohup command arguments & The command will run in the background. ## viewing and killing processes To view processes (use either): - $ top - $ htop To exit out of the process view: - q To kill, use top or htop to find the job PID. - $ kill *PID* If that doesn't work, use signal 9: - $ kill -9 *PID*