0

I'm a beginner in Linux, using Ubuntu.

I want to make it easier to login to a server using ssh.

In my institute, our login command is ssh -Y -p 4022 [email protected].

How can I make an alias for this?

terdon
  • 234,489
  • 66
  • 447
  • 667

2 Answers2

3

Add this to your ~/.ssh/config file (or create the file with this content):

Host cuplogin2
    User user
    Hostname cuplogin2.ibs.re.kr
    Port 4022
    ForwardX11Trusted yes

Now you can login using:

ssh cuplogin2

If you want, you can also shorten the name next to Host if you want, e.g. Host cl2. Then, you can login using ssh cl2.

pLumo
  • 22,231
  • 2
  • 41
  • 66
0

Quick answer You can add aliases into ~/.bashrc. This is the file used to initialize environments when you open a terminal. So you should add the following command into ~/.bashrc

# ssh alias
alias sshmein='ssh -Y -p 4022 [email protected]'

Do not forget the dot "." before filenames. You need to open a new terminal/ssh for the changes to be applied.

Moreover, if you ever opened ~/.bashrc, you might find the following thing at the end:

if [ -f ~/.bash_aliases ]; then
    . ~/.bash_aliases
fi

which means all things in ~/.bash_aliases will be "included" into ~/.bashrc. So I always put my customized commands under ~/.bash_aliases. This is the neater way.

The .bashrc can do many other things, for example

# extra PATH
PATH="$PATH:$HOME/Android/Sdk/platform-tools"
# joke commands
alias please='sudo'

If you want to apply some alias system-wide, edit /etc/profile, which is the .bashrc for all users.

terdon
  • 234,489
  • 66
  • 447
  • 667
Youran
  • 133
  • 6