Create a command to auto-login to some server.
Today we will see how to create a command to ssh a particular server to ease our life.
Here i have created a function ngessh to ssh a particular server with root and setup password less authentication for seamless experience.
1. Create function in starup file
I have used .bash_profile file to read this function every time my user log into bash shell.
[root@nglinux ~]# cat .bash_profile function ngessh() { a='ssh root@172.21.49.107' $a; echo; } [root@nglinux ~]#
Now this command will do ssh to the IP address 172.21.49.107 with root user.
2. Setup Password less authentication by generating key pair and transferring public key to other host.
I preferred to setup password less authentication and hence created by rsa key pair using below command.
[root@nglinux ~]# ssh-keygen [root@nglinux ~]# ls -altr .ssh/ total 48 -rw-r--r-- 1 saket1447583 staff 12463 Jun 2 07:11 known_hosts -rw-r--r-- 1 saket1447583 staff 411 Jun 2 07:20 id_rsa.pub -rw------- 1 saket1447583 staff 1679 Jun 2 07:20 id_rsa drwx------ 5 saket1447583 staff 170 Jun 2 07:20 . drwxr-xr-x+ 27 saket1447583 staff 918 Jun 2 07:32 .. [root@nglinux ~]#
Now we need to share the public key of the other user & host. The user of other server will put this public key into the authorized_keys file and then we can do password less login to his account.
[root@nglinux ~]# cat .ssh/authorized_keys ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDLx8V/VTFpVxd3dW4gGDLDA21qhQ8RnsUHm+PqNnw0ZDAbCypyf3enZWUvvuCsqgYaoYFFld7bXHRtKvdPBX5FHl81qzgQ6pnT8bC5Vh+FGn2G/kDypjvlAH+1KeMGB5+14zDq45tFL8aUroRsc0kuq9fEBvQtzoH7SbKA4jmKSj+lDExnVmJIxQM5f11bFIZu9ZVewDQ3lNPX7A6KP/awmzK+EKdS0tICi0wQo7RpbFiYAXNXVCwk9Gq9AOo19+tA5tpOUOLPEMcLO02gWHzgEkKkWUxvh6rVIdzjOhLGw79FY7lfVhMz6S3I/GSmbDf1tM2cH8ugY1QUzOyYYl6v saket1447583@01HW860271.local [root@nglinux ~]#
Output
We can see the output, how we are able to do password less authentication now.
[root@nglinux ~]# ngessh Welcome to | \ | |/ ___| | | (_)_ __ _ ___ __ | \| | | _ | | | | '_ \| | | \ \/ / | |\ | |_| | | |___| | | | | |_| |> < |_| \_|\____| |_____|_|_| |_|\__,_/_/\_\ NG Linux comes with ABSOLUTELY NO WARRANTY, to the extent permitted by applicable law. -bash: warning: setlocale: LC_CTYPE: cannot change locale (UTF-8): No such file or directory Mysql password is root/redhat PHPMyAdmin can be accessed at http://localhost/phpmyadmin Apache and FTP Server already setup. Your IP addr:10.0.2.15 addr:172.21.49.107 NGEL System Console can be accessed at URL http://localhost/system Run NGELINUX_HARDDISK_INSTALL to create partitions and install this live CD on your system hard disk Run NGELINUX_INSTALL to copy block by block your ISO file to a USB or Complete Hard disk [root@nglinux2 ~]#
Voila !! Similarly you can create your own functions that will work as commands in terminal.