Project

General

Profile

How to use a shared SSH config file » History » Version 9

Jon Goldberg, 11/09/2020 07:37 PM

1 9 Jon Goldberg
{{last_updated_at}} by {{last_updated_by}}
2
3 1 Jon Goldberg
# How to use a shared SSH config file
4
5
Do the following:
6
* In the Nextcloud shared folder, locate the following files: `Configurations/work-ssh-config`, `Configurations/joseph-ssh-config`.
7
* Create a `config.d` folder inside your `~/.ssh` folder.
8
* Create symlinks (aliases) to those files, e.g.:
9 3 Jon Goldberg
10 1 Jon Goldberg
```shell
11 5 Jon Goldberg
ln -s /home/jon/ownCloud/work/Configurations/work-ssh-config ~/.ssh/config.d/20-megaphone
12
ln -s /home/jon/ownCloud/work/Configurations/joseph-ssh-config ~/.ssh/config.d/30-joseph
13 1 Jon Goldberg
```
14
15
When you're done, running `ls -l` in the `config.d` folder should look something like this (note I have a third "personal" symlink:
16 2 Jon Goldberg
17 1 Jon Goldberg
```
18
zabuntu: ~/.ssh/config.d » ls -l                                                                                                                                                                                                  
19
total 0
20
lrwxrwxrwx 1 jon jon 43 Oct 20  2016 10-personal -> /home/jon/ownCloud/personal/ssh/10-personal
21
lrwxrwxrwx 1 jon jon 54 May 21  2017 20-work -> /home/jon/ownCloud/work/Configurations/work-ssh-config
22
lrwxrwxrwx 1 jon jon 56 Nov 27  2017 30-joseph -> /home/jon/ownCloud/work/Configurations/joseph-ssh-config
23
```
24
25 6 Jon Goldberg
* Add these lines anywhere in your `.bashrc` file (a hidden folder in your home directory).
26 2 Jon Goldberg
27 1 Jon Goldberg
```shell
28
function ssh()
29
{
30
    ssh-combine; /usr/bin/ssh $@
31
}
32
33
function rsync()
34
{
35
    ssh-combine; /usr/bin/rsync $@
36
}
37
38
function scp()
39
{
40
    ssh-combine; /usr/bin/scp "$@"
41
}
42
43
function ssh-combine()
44
{
45
    cat $HOME/.ssh/config.d/* > $HOME/.ssh/config
46
}
47
```
48 6 Jon Goldberg
49
If your username on your local machine isn't the same as your username on the remote machines, we'll also need to tell SSH to use a different default username.
50 8 Jon Goldberg
* Create a file in `~/.ssh/config.d` called `40-global`.  It doesn't need to be a symlink.
51
* The entire contents of this file should be:
52
53
```
54
Host *
55
  user dennis
56
```
57
Substitute your username for `dennis`.
58 7 Irene Meisel
59
Once the above setup is complete run ssh HOST and you should be connected.