Reload ssh config file
If you already use SSH config file and have a some nifty tip with you, do share it with the rest of us in the comment section. Please enter at least 3 characters 0 results found. Abhishek Prakash. Using SSH profiles can help you in cases where you regularly connect to various servers. Table of Contents. You may specify the port as well if you want. A better and easier way is to use SSH config file. Using SSH config file for easily connecting to remote servers The SSH config file allows you to create different profiles for different host configurations.
Let me show you how to use it. No need to restart any service. Space or tab indention are used for making the config file easily understandable. The Hostname can be the IP address of the server or a hostname that can be resolved on your network.
All the parameters like hostname, user and port are optional. You cannot save passwords in SSH config. I advise adding your public SSH key to the server for easy access. So if I try to use the main-server SSH profile, it will automatically take root user.
So, if you want to override a profile, you can do that using the -o option of the ssh command. Learn more. Asked 7 years, 8 months ago. Active 9 months ago. Viewed k times. Improve this question.
Casey Jones 55 6 6 bronze badges. Maxim Yefremov Maxim Yefremov 1, 3 3 gold badges 12 12 silver badges 15 15 bronze badges. You may use sudo service ssh restart to restart the service to take effect. But remember if you're connected through SSH, your session will be terminated.
Add a comment. Active Oldest Votes. Improve this answer. Thomas 13 13 bronze badges. Pathin Pathin 7 7 silver badges 6 6 bronze badges. What if I'm on an ssh connection? Use the "service" command.
Most services won't care, but there are a few that do because they're impacted by environment variables. For example, running "sudo" leaves the HOME environment variable to your non-root home directory. This doesn't work on Ubuntu There's an even less intrusive way to do this, without restarting the SSH service. From man sshd : sshd rereads its configuration file when it receives a hangup signal, SIGHUP, by executing itself with the name and options it was started with, e.
Steven K Steven K 4, 20 20 silver badges 23 23 bronze badges. Also, using a script makes sure the same parameters with the same values are set in the same way on every host where the script runs. There isn't just one way of doing it. I chose the following method because I believe it follows the "keep it simple" principle and has a pretty robust solution. So here is the script, followed by an explanation:.
The script starts with the shebang and some lines of comments. I like to use comments at the top to briefly describe what the script is supposed to do. Then I put in a debug switch with set -x. Try it out if you're not familiar with debugging. It comes in pretty handy when tracing errors in your script. I like to have all the variables I need to define in one place. They are found in the next few lines following the comments and before I define some functions.
You don't need to use functions, but I like them because they help give the script some structure. And the functions help you when it comes to troubleshooting. You could easily comment out large parts of your code the functions and focus on the sections that cause you trouble.
If you are not familiar with functions, please see the "Shell Function Definitions" section in the bash 1 manpage. This function outputs a brief instruction on how to use this script. It is called when the script is executed with the option -h or -? Before changing anything on a production system, it's best practice to create a backup of the files that are subject to change. Now that I have a backup, I'll edit the file. First, I remove all lines beginning with the specified parameters because I don't know how often they already occur in the file.
I need to make sure that only my desired configuration exists in the end. This is the job of the sed command running in a for loop. Since my parameters are stored as elements in a Bash array, I can loop over all the array elements to remove them.
You can find information about Bash arrays in the "Arrays" section on the bash 1 manpage.
0コメント