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 user@example.com.

How can I make an alias for this?

0
2

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.

4
  • Thanks for reply! Is it impossible to omit ssh? Nov 24 '21 at 7:57
  • Not sure what you mean. You can make an alias to ssh like alias s=ssh, so then it would be s cl2, but isn't ssh short enough?
    – pLumo
    Nov 24 '21 at 8:07
  • @HyungJoeKwon alias s='ssh cl2' is possible. Nov 24 '21 at 8:26
  • Thanks!! It really helps me! Nov 25 '21 at 6:18
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 user@cuplogin2.ibs.re.kr'

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.

0

Not the answer you're looking for? Browse other questions tagged or ask your own question.