Yuxuan Yuan

Personal webpage

Welcome to my page. In this site, I will regularly upload some useful stuff regarding bioinformatics


Server environment settings

Server environment settings are useful to quickly remember particular command lines and make it easier to install bioinformatics tools. Here I mainly talk about profile, bashrc and vimrc settings.

Customised Bash/zsh/sh

Different people have different habits in using Bash, sh or zsh. For instance, sometimes people use aliases to represent command lines. Here I give some tips in bash environment settings.

Make a profile

A profile can be used in Linux ENV to customise your aliases to make the command line easy to remember. Here I list the settings in .myProfile to show how to set shortcuts

############# Andy's Profile ###########
##### alias
alias ll='ls -trhl';
alias la='ls -la';
alias lh='ls -lh';
alias h='history';
alias m='more';
alias rm='rm -i';
alias e='exit';
alias ..='cd ..';
alias dir='pwd';
alias cp='cp -i';
alias mycp='rsync -avh --progress';
alias mac2unix="perl -pi -e 's/\r/\n/g' ";
alias readlink='readlink -f';
export SVN_EDITOR=vim
alias desktop='cd ~/Desktop';
alias downloads='cd ~/Downloads';
alias documents='cd ~/Documents';
alias tools='cd ~/Tools';
alias md='cd ~/modulefiles';

umask 027

if [ -d $HOME/bin ]; then
        BIN_EXIST=`echo $PATH | grep $HOME/bin`;
        if [ -z "$BIN_EXIST" ]; then
                PATH=$PATH:$HOME/bin
        fi
fi

thisHost=`hostname`

##### Server specific settings #####
# my remote desktop
mypc() { 
    THIS_USER=$1; if [ $# -eq 0 ]; then THIS_USER='yyuan'; fi
    ssh -X ${THIS_USER}@192.168.51.150;
}
 
HISTSIZE=1000
export HISTCONTROL=ignoredups
export HISTIGNORE="pwd:ls:ll:la:history:exit:h:top:cd ..:"
export EDITOR=/usr/bin/vim

Set .bashrc/.zshrc

.bashrc or .zshrc, profile or bash_profile is automatically executed when log in Linux/MacOS system. If there is no such a file, you may create one in your HOME directory. In this file, you may source your .myProfile to make all your aliases work properly on your machine. You may also set your software PATH in this file.

source $HOME/.myProfile
export LANGUAGE=en_US.UTF-8
export LC_ALL=en_US.UTF-8
export LANG=en_US.UTF-8
export LC_TYPE=en_US.UTF-8

Customise text editor

In Linux/MacOS system, text editors are always used. There are several text editors such as nano, emacs, and vim. Here I list how to set vim.

  • Ensure .vimrc is in your HOME directory. If there is no such a file, you may create one.
  • The content inside .vimrc is like:
syntax on

set nu
set tabstop=4
set hlsearch
set incsearch
set cursorline
hi CursorLine ctermbg=lightgrey ctermfg=red
hi CursorLine ctermbg=lightgrey ctermfg=red 

Set public keys

Sometimes, you don’t want to type the password for the servers, you may set the public keys to avoid entering password.

Firstly, you may need to generate SRA keys using:

$ ssh-keygen -t rsa

An easy way is to press the ‘enter’ button till it completes. Then you may use the command line below to set the public keys

If you don’t remember if there is a public key, you can go to the folder and check

$ cd ~/.ssh
$ ls -l

Usually, you can get

-rw-------  1 yyuan  staff   1.6K 11 Mar  2018 id_rsa
-rw-r--r--  1 yyuan  staff   411B 11 Mar  2018 id_rsa.pub

If you don’t have such files, you may need to generate one as shown above.

After that, you will have two ways to set auto login.

The first one is

$ ssh-copy-id yyuan@your.server.address

Enter your password and then the settings will be OK and you can login the server without a password.

The second method is to copy your public key in your local machine to the server

$ cat ~/.ssh/id_rsa.pub 

Copy the public key and then in your remote server, create a file name authorized_keys and paste the copied public key

$ vim ~/.ssh/authorized_keys

After that you can login to your remote server without typing a password.

Note: you may want to check the port used on your server.

Set a remote login

You may set your PC to be logged in from other pc/laptop. Firstly, you may ensure you have a linux installed on your machine. Then follow the steps below to finish the settings.

  1. install openssh-server
$ sudo apt-get install openssh-server
  1. Check if you have the files below
$ cd /etc/ssh && ll
-rw------- 1 root root    668 Apr 10  2016 ssh_host_dsa_key
-rw-r--r-- 1 root root    603 Apr 10  2016 ssh_host_dsa_key.pub
-rw------- 1 root root    227 Apr 10  2016 ssh_host_ecdsa_key
-rw-r--r-- 1 root root    175 Apr 10  2016 ssh_host_ecdsa_key.pub
-rw------- 1 root root    399 Apr 10  2016 ssh_host_ed25519_key
-rw-r--r-- 1 root root     95 Apr 10  2016 ssh_host_ed25519_key.pub
-rw------- 1 root root   1675 Apr 10  2016 ssh_host_rsa_key
-rw-r--r-- 1 root root    395 Apr 10  2016 ssh_host_rsa_key.pub

If you don’t have them, you may generate them using:

$ sudo dpkg-reconfigure openssh-server
  1. Enable remote log in
$ sudo service ssh start


Copyright@Andy’s blog » Server environment settings

Rewards

cancel

Thanks for your support and I will work even harder!

scan
scan
Reward by scaning the QR Code

OpenalipayReward by scaning the QR Code