|
| 1 | +--- |
| 2 | +layout: post |
| 3 | +title: HOWTO Obtain new Openshift token from Xterm |
| 4 | +date: 2025-02-14 09:15:16 |
| 5 | +description: OpenShift login token expired because tokens are, by default, valid for a limited time (e.g., 24 hours). Follow these steps to obtain a new token and continue working with the cluster. |
| 6 | +tags: OpenShift token xterm CLI text-web-browser lynx |
| 7 | +categories: OpenShift |
| 8 | +--- |
| 9 | + |
| 10 | +# How to Obtain a New Token for OpenShift from xterm |
| 11 | + |
| 12 | +OpenShift login tokens expire because they are, by default, valid for a limited time (e.g., 24 hours). One way to obtain a new token is by SSHing into the controller machine and |
| 13 | +running the [relogin.sh script](https://github.com/dsariel/scripts/blob/master/OpenShift/relogin.sh). See the content below: |
| 14 | + |
| 15 | + |
| 16 | +# OpenShift Token Refresh |
| 17 | + |
| 18 | +OpenShift login tokens expire because they are, by default, valid for a limited time (e.g., 24 hours). One way to obtain a new token is by SSHing into the controller machine and running the relogin.sh script. |
| 19 | + |
| 20 | +<iframe src="iframe.php?url=https://github.com/dsariel/scripts/blob/master/OpenShift/relogin.sh" width="100%" height="400px"></iframe> |
| 21 | + |
| 22 | + |
| 23 | + |
| 24 | +# ------------------------------ |
| 25 | + |
| 26 | + |
| 27 | +<iframe |
| 28 | + src="https://codepen.io/team/codepen/embed/preview/PNaGbb" |
| 29 | + style="width:100%; height:300px;" |
| 30 | +></iframe> |
| 31 | +
|
| 32 | +# ------------------------------ |
| 33 | + |
| 34 | +# OpenShift Token Refresh |
| 35 | + |
| 36 | + |
| 37 | +```html |
| 38 | +<style> |
| 39 | +.gist .gist-file { |
| 40 | + background-color: #a8a2a2 !important; |
| 41 | + color: #f548f2 !important; |
| 42 | +} |
| 43 | +</style> |
| 44 | + |
| 45 | +<script src="https://gist.github.com/dsariel/a68bdb55784f23b59f64aa6a6929b73d.js"></script> |
| 46 | +``` |
| 47 | + |
| 48 | +# ------------------------------ |
| 49 | + |
| 50 | + |
| 51 | + |
| 52 | +```bash |
| 53 | +<!-- Embed script from raw GitHub content --> |
| 54 | +curl -s https://raw.githubusercontent.com/dsariel/scripts/master/OpenShift/relogin.sh | cat |
| 55 | + |
| 56 | +``` |
| 57 | + |
| 58 | +and using a text-based web browser on the remote server if connecting via the web console is not an option. Follow these steps to obtain a new token and continue working with the cluster: |
| 59 | + |
| 60 | +## Steps to Obtain a New Token |
| 61 | + |
| 62 | +1. **Install a Text-Based Browser**\ |
| 63 | + Install `lynx`, a command-line browser, to access the token request page: |
| 64 | + |
| 65 | + ```bash |
| 66 | + sudo yum install lynx -y |
| 67 | + ``` |
| 68 | + |
| 69 | +2. **Retrieve a password for the `kubeadmin` user**\ |
| 70 | + If you are using the default `kubeadmin` user, retrieve the password from the installation directory: |
| 71 | + |
| 72 | + ```bash |
| 73 | + cat ~/.kube/kubeadmin-password |
| 74 | + ``` |
| 75 | + |
| 76 | + Use this password to log in as `kubeadmin` in the browser interface during the next stage. |
| 77 | + |
| 78 | +3. **Access the Token Request Page**\ |
| 79 | + Use `lynx` to navigate to the token request page: |
| 80 | + |
| 81 | + ```bash |
| 82 | + lynx https://oauth-openshift.apps.ocp.openstack.lab/oauth/token/request |
| 83 | + ``` |
| 84 | + |
| 85 | +4. **Obtain a New Token**\ |
| 86 | + Once logged in, obtain a new token. The login command will look like this: |
| 87 | + |
| 88 | + ```bash |
| 89 | + oc login --token=sha256~<...> --server=https://api.ocp.openstack.lab:6443 |
| 90 | + ``` |
| 91 | + |
| 92 | + |
0 commit comments