How to add a different username in ssh config for remote server ssh to save our time ?
Suppose you used to login via a different username on servers rather than the local user id.
One option is to add the username each time using below syntax:
# ssh server-name -l username OR, # ssh username@server-name
OR,
An easy way to save our little time is to add this username in our config file.
Today in this post, we will look how to add this username and similar options in the config file.
Lets see how to do this.
I. Adding Username in Configuration File
$ id -a uid=saket(saket) gid=20(staff) groups=20(staff),1025(imac_users_group),12(everyone),62(netaccounts),702(com.ngelinux.sharepoint.group.2),701(com.ngelinux.sharepoint.group.1) $ $ cat .ssh/config User webuser $ $ ssh server2 ******************************************************************************** !!!WARNING!!! ******************************************************************************** This system is a restricted access system. All activity on this system is subject to monitoring. Information collected that is malicious, unauthorized or unlawful, may be provided to the relevant authorities for further action. By continuing past this point, you expressly consent to this monitoring. ******************************************************************************** Last login: Tue Apr 16 18:05:10 2019 from 17.168.84.100 ******************************************************************************** Hostname: nwk-gcsrshp-lapp01.corp.ngelinux.com Hypervisor: XENU ghert23.ngelinux.com Location | Env: India | PROD Kernel | OS | Snapshot: 2.6.32-754.10.1.el6 | OL 6.10 | 6-2019.3.1 Info on snapshots: https://web.ngelinux.com/docs/DOC-1371850 Cores | Mem: 8 | 11.7 GB Applications: web, max ******************************************************************************** ******************************************************************************** -bash: warning: setlocale: LC_CTYPE: cannot change locale (UTF-8): No such file or directory -bash-4.1$ id uid=webuser(webuser) gid=10000(aplstaff) groups=10000(aplstaff) -bash-4.1$
II. Sample Config File with Global & Individual Server Options
$ cat .ssh/config
## Global Options
Host *
ForwardAgent no
ForwardX11 no
ForwardX11Trusted yes
User webuser
Port 22
Protocol 2
ServerAliveInterval 60
ServerAliveCountMax 30
## override options as per host
Host server2
HostName server1.ngelinux.com
User testuser
Port 4200
IdentityFile /nfs/shared/users/ngelinux/keys/server1/id_rsa
In the above options, we can see the option “User” is used to mention the username.
Similarly we have a lot of options which can be seen in the same file above where we can modify the port number, and can mention individual options for different servers.
Hence, now you can mention any different username for all/specific servers to save your little bit time.
