# ssh as different user

## ppeetteerr

Ok so my username on my home computer is peter.  My user name on host.com is ppeetteerr.  In the past I've done 

```
 ssh ppeetteerr@host.com 
```

 or when I'm feeling adventurous 

```
 ssh -l ppeetteerr host.com
```

My question is: is there a way to change my default user name when I ssh.  So I can just ssh host.com and it logs me in as ppeetteerr?

----------

## Aleksi Halkola

you can do that in ~/.ssh/config. Just add teh following

Host host.com IP

HostName full.host.name.com

User ppeetteerr

----------

## think4urs11

```
cat ~/.ssh/config

Host schnickschnack

 HostName host.com

 User ppeetteerr

me@box $ ssh schnickschnack
```

----------

## mimosinnet

This is somehow related. I have a user (joanet) and I am the root in the same box. I ssh to the same external boxes, so I thought I could make a symbolic link and root could use joanet configuration:

```
# ln -s /home/joanet/.ssh /root/.ssh
```

```
# ls -lisah /root

14417927    0 lrwxrwxrwx  1 root root   17  9 jun 19:46 .ssh -> /home/joanet/.ssh
```

When I try to ssh from root:

# ssh mimosinnet

I get the following message:

```
Bad owner or permissions on /root/.ssh/config
```

I understand the message: I am trying to ssh from root and the file owner is joanet:

```
# ls -lisah /root/.ssh/config

11337740 4,0K -rw------- 1 joanet joanet 359  9 jun 20:04 /root/.ssh/config
```

This is my /root/.ssh/config

```
# cat /root/.ssh/config

Host mimosinnet

        User mimosinnet

        IdentityFile ~/.ssh/id_dsa

        ForwardX11 yes

        Compression yes

        ForwardX11Trusted yes
```

If I copy my joanet configuration to root, I have joanet ssh configuration working in root:

```
cp -r /home/joanet/.ssh .
```

Is there a possibility to use symbolic links to not have to maintain two similar ssh configurations (joanet and root)?

Thanks!

----------

## Dieter@be

afaik the owner of the ssh config must always be the user itself

----------

## mimosinnet

 *Dieter@be wrote:*   

> afaik the owner of the ssh config must always be the user itself

 

Good to know! This leads me towards finding another strategy. Thanks a lot for the answer!  :Smile: 

----------

## infinite1der

 *mimosinnet wrote:*   

>  *Dieter@be wrote:*   afaik the owner of the ssh config must always be the user itself 
> 
> Good to know! This leads me towards finding another strategy. Thanks a lot for the answer! 

 

See also sshd_config: StrictModes

----------

## mimosinnet

 *infinite1der wrote:*   

> See also sshd_config: StrictModes

 

Thanks very much for the tip. I have tried StrictModes with the abovementioned configuration (symbolic link of .ssh from root to user) and still unable to connect:

```
# grep StrictModes /etc/ssh/sshd_config

StrictModes no

# ssh mimosinnet

Bad owner or permissions on /root/.ssh/config
```

These are the permissions of the config file:

```
11339658 4,0K -rw-------  1 joanet joanet  466 11 jun 05:12 config
```

Nevertheless, if I change the owner and permissions of the config file (it does not work if I make the file writtable for the group):

```
11339658 4,0K -rw-r-----  1 root   users   466 11 jun 05:12 config
```

I am able to log from root and the user.    :Very Happy: 

Great! Wonderful! Thanks a lot!

Update: Nevertheless, this happens independently of the value of StrictModes.   :Exclamation:   :Question: 

----------

